Discuss Scratch

fireballash
Scratcher
2 posts

A better way to tell what keys are being pressed

While trying to make a keyboard in scratch that doesn't just use the “ask” block, I've noticed that there isn't really a good way to tell what keys are being pressed without having a really long script of. “Key __ pressed” over and over again. I suggest a new sensing block that tells you what keys are currently being pressed. I'm not super sure what it would do if multiple keys were pressed, but I can see it working with either, giving the first key that has been held, the most recent key to be pressed, or just putting them all together (so like if someone was holding F and G at the same time it would return FG).
Elijah999999
Scratcher
1000+ posts

A better way to tell what keys are being pressed

Turbowarp has a “last key pressed” operator block. This would be something like this? To avoid confusion, I feel like the suggested block should only be able to report one key at a time.
fireballash
Scratcher
2 posts

A better way to tell what keys are being pressed

Yeah I think that would work better too.
Xzillox
Scratcher
1000+ posts

A better way to tell what keys are being pressed

there are a few projects the absence of this block has prevented me from creating so it would certainly make it MUCH easier to make said projects
RethinkingVoxels
Scratcher
1000+ posts

A better way to tell what keys are being pressed

You could do

define last key pressed
// put this in run without screen refresh
set [alphabet v] to [abcdefghijklmnopqrstuvwxyz1234567890]
set [i v] to (1)
repeat (length of (alphabet))
set [i of alphabet v] to (letter (i) of (alphabet))
if <key (i of alphabet) pressed?> then
set [last key pressed] to (i of alphabet)
end
change [i v] by (1)

Last edited by RethinkingVoxels (Jan. 20, 2024 14:58:19)

EDawg2011
Scratcher
1000+ posts

A better way to tell what keys are being pressed

This is a duplicate. Please continue the discussion here so that the conversation is in one place.
Maybe?

Last edited by EDawg2011 (Jan. 20, 2024 15:43:54)

k7e
Scratcher
1000+ posts

A better way to tell what keys are being pressed

This could cause translation errors. Currently there are no reporter blocks that report values that are different in different languages. What if this happens?
<(last key pressed :: sensing) = [down arrow]>
Then it won't work for speakers of other languages because the block would report whatever “down arrow” is in that language, not the English words “down arrow”.

Last edited by k7e (Jan. 20, 2024 16:07:03)

cosmosaura
Scratch Team
1000+ posts

A better way to tell what keys are being pressed

EDawg2011 wrote:

This is a duplicate. Please continue the discussion here so that the conversation is in one place.
Maybe?
Thanks for the link! It does look like this is a duplicate topic so I'll close it to keep the conversation all in one place. Please use the existing topic in the link above.

Powered by DjangoBB