Discuss Scratch
- -N6-
-
35 posts
"Key Pressed" variable
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.
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
Last edited by -N6- (Nov. 27, 2015 16:53:27)
- The_Kitty_Eevee
-
100+ posts
"Key Pressed" variable
HUGE SUPPORT YES THANK YOU 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
- ItchyCatIII
-
500+ posts
"Key Pressed" variable
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
I support the idea, although I'm not sure how useful it would be for me, it could probably be useful to others, and it does seem tedious to have to make 26 of the same if/else statements.
But anyway, what happens if multiple keys are pressed? Does it report all of them?
- -N6-
-
35 posts
"Key Pressed" variable
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
I support the idea, although I'm not sure how useful it would be for me, it could probably be useful to others, and it does seem tedious to have to make 26 of the same if/else statements.
But anyway, what happens if multiple keys are pressed? Does it report all of them?
It could report the first letter pressed (by ms?)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
I support the idea, although I'm not sure how useful it would be for me, it could probably be useful to others, and it does seem tedious to have to make 26 of the same if/else statements.
But anyway, what happens if multiple keys are pressed? Does it report all of them?
- Zekrom01
-
1000+ posts
"Key Pressed" variable
I support. However, there are blocks it can't fit in. If it goes in one of those blocks, the edges of the block should turn red.
- ChildCritic
-
500+ posts
"Key Pressed" variable
I'd prefer
(Currently pressed key::sensing)So that it does not get confused with the boolean of the
<key [ v] pressed?>//boolean scratchblocks can not do oneSupport for the rename.
- Prinseskat
-
1000+ 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:
Also, I think that a
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.
- stickfiregames
-
1000+ posts
"Key Pressed" variable
Semi-support, and it should report the last key pressed if multiple keys are pressed at once.
The reason I don't fully support is that the arrow keys have different names in different languages, so it might confuse people who try to compare the names in their own language, and it doesn't work because the block is reporting them in English. This isn't an issue for the space bar because the block could just return a space.
The reason I don't fully support is that the arrow keys have different names in different languages, so it might confuse people who try to compare the names in their own language, and it doesn't work because the block is reporting them in English. This isn't an issue for the space bar because the block could just return a space.
- bigpuppy
-
1000+ posts
"Key Pressed" variable
Hi! SUPPORT
Please be constructive and tell us a reason instead of just saying “Support” in the future.
Thanks, and Scratch on

- LordOfMuffins
-
100+ posts
"Key Pressed" variable
No support. Scratch doesn't work like that. All Booleans (the pointy blocks) only report true or false. Your
<key pressed ::sensing>block wouldn't work. It would work better as a
(Last key?::sensing)block. Even then, there are workarounds that would take the place of this.
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
- braxbroscratcher
-
1000+ posts
"Key Pressed" variable
The ST is perfectly fine with hacking the JSON, as long as the end result is a block that is still sensible. (Which this would be) 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.
- WolfCat67
-
1000+ posts
"Key Pressed" variable
Just going to put it out there that many people don't know how to hack JSON, so I'm going to have to support with this one. The workaround seems too complex and also requires hacking, which I can't do. I also struggle with Custom Blocks, but I'm getting better with them.The ST is perfectly fine with hacking the JSON, as long as the end result is a block that is still sensible. (Which this would be) 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:
-Snip-
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.
- dvargasews
-
500+ posts
"Key Pressed" variable
I think that it should be the last key to be released in that case.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
I support the idea, although I'm not sure how useful it would be for me, it could probably be useful to others, and it does seem tedious to have to make 26 of the same if/else statements.
But anyway, what happens if multiple keys are pressed? Does it report all of them?
- dvargasews
-
500+ posts
"Key Pressed" variable
I agree with your suggestion, but there's a quicker workaround.
define record last key pressed for [input]
if <key (input) pressed?> then
set [last key pressed v] to (input)
end
when green flag clicked
forever
record last key pressed for [a] :: more blocks
record last key pressed for [b] :: more blocks
record last key pressed for [c] :: more blocks
record last key pressed for [d] :: more blocks
...
end
- milesanderson1
-
1 post
"Key Pressed" variable
No support. Scratch doesn't work like that. All Booleans (the pointy blocks) only report true or false. Your<key pressed ::sensing>block wouldn't work. It would work better as a(Last key?::sensing)block. Even then, there are workarounds that would take the place of this.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
- hello1964
-
84 posts
"Key Pressed" variable
Actually you don't have to hack the JSON code because you can put a variable there 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.
Last edited by hello1964 (Feb. 26, 2020 03:05:55)
- PkmnQ
-
1000+ posts
"Key Pressed" variable
You used to have to do that in Scratch 2.0.Actually you don't have to hack the JSON code because you can put a variable there 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.