Discuss Scratch
- the2000
-
Scratcher
1000+ posts
"Key Pressed" variable
No support.…That's not a workaround. That would just return “true” or “false”, not the keys currently being pressed. Also, don't quote the OP.
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
Edit: Ayy, king of the page!
Last edited by the2000 (Feb. 1, 2021 14:45:51)
- EatNYeet
-
Scratcher
500+ posts
"Key Pressed" variable
Only workaround I could think of is this:
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.
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
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 pressedwhich I don't think the ST really approves of.
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
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
Support!give a reason why,
also
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
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
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
And it would just return the most recent key that was pressed down
- medians
-
Scratcher
1000+ posts
"Key Pressed" variable
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.
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
look at this video it has all the info (no JSON editing)waht? is this adverts?
https://www.youtube.com/watch?v=dhkm7z8MFno
- Tris_das_Einhorn
-
Scratcher
100+ posts
"Key Pressed" variable
Definitely support a
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):
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
last key pressed? :: sensing reporterblock, for a few reasons:
-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
That one obviously does not count, as that's literally the purpose of the block.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 k7e (Nov. 22, 2023 00:53:06)
- medians
-
Scratcher
1000+ posts
"Key Pressed" variable
what if you click multiple inputs
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
What use would a block that reports a list have?what if you click multiple inputsNo support, what if multiple keys are pressed at the same time?It could just report a list or sth then.
- 106809nes
-
Scratcher
1000+ posts
"Key Pressed" variable
deleted…
Last edited by 106809nes (Nov. 22, 2023 01:16:46)















