Discuss Scratch

-N6-
Scratcher
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

Last edited by -N6- (Nov. 27, 2015 16:53:27)

The_Kitty_Eevee
Scratcher
100+ posts

"Key Pressed" variable

-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

HUGE SUPPORT YES THANK YOU
DaSpudLord
Scratcher
1000+ posts

"Key Pressed" variable

Support!
ItchyCatIII
Scratcher
500+ posts

"Key Pressed" variable

-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


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-
Scratcher
35 posts

"Key Pressed" variable

ItchyCatIII wrote:

-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


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?

ItchyCatIII wrote:

-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


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?)
Zekrom01
Scratcher
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
Scratcher
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 one
Support for the rename.
Prinseskat
Scratcher
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:
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.
jacquesimo
Scratcher
100+ posts

"Key Pressed" variable

SUPPORT
stickfiregames
Scratcher
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.
bigpuppy
Scratcher
1000+ posts

"Key Pressed" variable

jacquesimo wrote:

SUPPORT
Hi!
Please be constructive and tell us a reason instead of just saying “Support” in the future.

Thanks, and Scratch on
LordOfMuffins
Scratcher
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.

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

braxbroscratcher
Scratcher
1000+ 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.
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)
WolfCat67
Scratcher
1000+ posts

"Key Pressed" variable

braxbroscratcher wrote:

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:

-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.
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)
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.
dvargasews
Scratcher
500+ posts

"Key Pressed" variable

ItchyCatIII wrote:

-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


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?
I think that it should be the last key to be released in that case.
dvargasews
Scratcher
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
Scratcher
1 post

"Key Pressed" variable

LordOfMuffins wrote:

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.

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

hello1964
Scratcher
84 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.
Actually you don't have to hack the JSON code because you can put a variable there

Last edited by hello1964 (Feb. 26, 2020 03:05:55)

JHAMMER3
Scratcher
29 posts

"Key Pressed" variable

I like that idea. It sounds really handy.
PkmnQ
Scratcher
1000+ posts

"Key Pressed" variable

hello1964 wrote:

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.
Actually you don't have to hack the JSON code because you can put a variable there
You used to have to do that in Scratch 2.0.

Powered by DjangoBB