Discuss Scratch

the2000
Scratcher
1000+ posts

"Key Pressed" variable

GamerMarcus646 wrote:

No support.
An easy work around would be to have the following scripts and just using the “key pressed?” variable.
when green flag clicked
forever
set [key pressed? v] to <key [space v] pressed?>
end
…That's not a workaround. That would just return “true” or “false”, not the keys currently being pressed. Also, don't quote the OP.

Edit: Ayy, king of the page!

Last edited by the2000 (Feb. 1, 2021 14:45:51)

MDCCCLXVII
Scratcher
1000+ posts

"Key Pressed" variable

bump
EatNYeet
Scratcher
500+ posts

"Key Pressed" variable

Only workaround I could think of is this:

when green flag clicked
forever
if <key [right arrow v] pressed?> then
set [rightpress v] to [1]

else
set [rightpress v] to [0]
end
end

And repeat until done for every key.



My method is really inefficient and I can't think of any other one, so I can't support this suggestion enough.
Beast_chick
Scratcher
3 posts

"Key Pressed" variable

Prinseskat wrote:

Support, this would be so useful for projects involving typing in some way! Unless you want 26 if-statements, the only way to sort-of get this is to hack the JSON code:
define find key currently being pressed
set [i v] to [1]
set [chars v] to [abcdefghijklmnopqrstuvwxyz]
set [key v] to []//variable that'll "return" the key pressed - blank if no key pressed
repeat (length of (chars))
set [current char v] to (letter (i) of (chars))
if <key (current char) pressed> //will need to "hack" (edit JSON code) to get variable in key pressed boolean
set [key v] to (current char)
stop [this script v]
end
change [i v] by [1]
end
which I don't think the ST really approves of.
Also, I think that a
(last key pressed::sensing)
would work, since it'll return a value even if a key is not currently pressed (which could be useful in some situations). It also fixes the problem of two keys being pressed at the same time.
OhOkSir12345
Scratcher
1000+ posts

"Key Pressed" variable

DaSpudLord wrote:

Support!
give a reason why,
also

-N6- wrote:

Hi,

Please could you add a variable block for when a key is pressed (to keep scratchers from drawing out loads of different if-statements)?

E.g.
when green flag clicked
forever
if <key [any v] pressed?> then
add <key pressed> to [text v]

end
end

<key pressed>::sensing
sharkode
Scratcher
1000+ posts

"Key Pressed" variable

No support, what if multiple keys are pressed at the same time?
DogJunior101
Scratcher
50 posts

"Key Pressed" variable

trtryr6y46

Last edited by DogJunior101 (Sept. 18, 2022 18:24:46)

memer0boi
Scratcher
1 post

"Key Pressed" variable

look at this video it has all the info (no JSON editing)
https://www.youtube.com/watch?v=dhkm7z8MFno
k7e
Scratcher
1000+ posts

"Key Pressed" variable

There are currently no reporter blocks that report different things in different languages. If this block was implemented, and someone used “if key pressed = space”, then someone viewed the project in Japanese, that would report false even if they pressed the space key, because it would report a Japanese character instead of the word “space”.

Last edited by k7e (Nov. 16, 2023 03:26:10)

cookieclickerer33
Scratcher
1000+ posts

"Key Pressed" variable

k7e wrote:

There are currently no reporter blocks that report different things in different languages. If this block was implemented, and someone used “if key pressed = space”, then someone viewed the project in Japanese, that would report false even if they pressed the space key, because it would report a Japanese character instead of the word “space”.
*crickets*
(Language::pen)

Last edited by cookieclickerer33 (Nov. 16, 2023 15:01:12)

cookieclickerer33
Scratcher
1000+ posts

"Key Pressed" variable

Also it would only return blocks detectable with the “key pressed” block

And it would just return the most recent key that was pressed down
medians
Scratcher
1000+ posts

"Key Pressed" variable

lucky_rocket_ship wrote:

Please give an example …
?
If you're wondering, 2.0 didn't allow you to put variables in the key pressed block without JSON editing.

sharkode wrote:

No support, what if multiple keys are pressed at the same time?
It could just report a list or sth then.
TheEpikGamer211
Scratcher
1000+ posts

"Key Pressed" variable

memer0boi wrote:

look at this video it has all the info (no JSON editing)
https://www.youtube.com/watch?v=dhkm7z8MFno
waht? is this adverts?
Tris_das_Einhorn
Scratcher
100+ posts

"Key Pressed" variable

Definitely support a
last key pressed? :: sensing reporter
block, for a few reasons:

ItchyCatIII wrote:

-snip-
…and it does seem tedious to have to make 26 of the same if/else statements.

And that's only for English! Hungarian has 44 letters, 18 of which aren't supported by the dropdown in the “key pressed?” block. And the cyrillic alphabet isn't supported at the moment either. So if you want to detect input from someone using a keyboard with diacritics or with a different alphabet, you have to use this workaround (and anticipate the likely input characters of those using the project):

<key (join [ ] [ű]) pressed?>

Or, you can index a string/list and/or use the custom block previously mentioned, but not everyone can be expected to know or be willing to use a JSON hack.

It would make the key press detection feature so much more intuitive to use if it could just detect any key press (returning only the most recent one, of course). It would also be very helpful for Scratchers who use the editor in a language other than English. 100% support
Wonkymoon8
Scratcher
100+ posts

"Key Pressed" variable

i dont understand what you are asking for, but keep in mind booleans can be put as numeric inputs, and i believe true is 1 and false is 0. idk if that really helps though because i dont fully understand what you are asking.
k7e
Scratcher
1000+ posts

"Key Pressed" variable

cookieclickerer33 wrote:

k7e wrote:

There are currently no reporter blocks that report different things in different languages. If this block was implemented, and someone used “if key pressed = space”, then someone viewed the project in Japanese, that would report false even if they pressed the space key, because it would report a Japanese character instead of the word “space”.
*crickets*
(Language::pen)
That one obviously does not count, as that's literally the purpose of the block.

Last edited by k7e (Nov. 22, 2023 00:53:06)

undeterminstic
Scratcher
1000+ posts

"Key Pressed" variable

what if you click multiple inputs
medians
Scratcher
1000+ posts

"Key Pressed" variable

undeterminstic wrote:

what if you click multiple inputs

medians wrote:

sharkode wrote:

No support, what if multiple keys are pressed at the same time?
It could just report a list or sth then.
k7e
Scratcher
1000+ posts

"Key Pressed" variable

medians wrote:

undeterminstic wrote:

what if you click multiple inputs

medians wrote:

sharkode wrote:

No support, what if multiple keys are pressed at the same time?
It could just report a list or sth then.
What use would a block that reports a list have?
106809nes
Scratcher
1000+ posts

"Key Pressed" variable

deleted…

Last edited by 106809nes (Nov. 22, 2023 01:16:46)

Powered by DjangoBB