Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Key detection
- DangerPuppy10
- Scratcher
500+ posts
Key detection
So, I'm making a game where it needs to detect which key has been pressed.
Not with:
Not with:
<touching [ v] ?>For example, I press the key “a”, and it shows on a variable what key I pressed: a
웃
WORSHIP RUBBER DUCK!!!!
I shall
I live in the suggestions sub-forum.
I might move into a 5-star forum!! I think it's called A“bout Scratch”?
YIPPEEEEEE
It would be greatly appreciated if you gave me an internet!
Workaround chart:
- -stxllxr
- New Scratcher
100+ posts
Key detection
define last key pressedthis is the simplest way to detect the last key pressed, however holding down b then pressing a breaks it, so I recommend addjng a wait until after the custom block, not inside the custom block since the custom block needs “run without screen refresh”.
set [i v] to (1)
repeat (length of [abcdefghijklmnopqrstuvwxyz 1234567890]
if <key (letter (i) of [abcdefghijklmnopqrstuvwxyz 1234567890]) pressed?> then
set [last key pressed v] to (letter (i) of [abcdefghijklmnopqrstuvwxyz 1234567890
end
change [i v] by (1)
Last edited by -stxllxr (March 31, 2024 01:21:29)
- DangerPuppy10
- Scratcher
500+ posts
Key detection
I did this, but. The variable “i” was set to 1, meaning it will only work if the key “a” was pressed. If I set it to 2, then it only works if I press the letter b.define last key pressedthis is the simplest way to detect the last key pressed, however holding down b then pressing a breaks it, so I recommend addjng a wait until after the custom block, not inside the custom block since the custom block needs “run without screen refresh”.
set [i v] to (1)
repeat (length of [abcdefghijklmnopqrstuvwxyz 1234567890]
if <key (letter (i) of [abcdefghijklmnopqrstuvwxyz 1234567890]) pressed?> then
set [last key pressed v] to (letter (i) of [abcdefghijklmnopqrstuvwxyz 1234567890
웃
WORSHIP RUBBER DUCK!!!!
I shall
I live in the suggestions sub-forum.
I might move into a 5-star forum!! I think it's called A“bout Scratch”?
YIPPEEEEEE
It would be greatly appreciated if you gave me an internet!
Workaround chart:
- -stxllxr
- New Scratcher
100+ posts
Key detection
I forgot to add a change i by one after the if block, editing now… I did this, but. The variable “i” was set to 1, meaning it will only work if the key “a” was pressed. If I set it to 2, then it only works if I press the letter b.
Last edited by -stxllxr (March 31, 2024 01:21:55)
- invalidaccess
- Scratcher
100+ posts
Key detection
Last edited by invalidaccess (March 31, 2024 19:28:37)
- MikaelZayaan
- Scratcher
2 posts
Key detection
“our server is scratch'ing its head” did you delete it or something i kinda made it but a little bit weird
https://scratch.mit.edu/projects/992550669/
check this out
- DangerPuppy10
- Scratcher
500+ posts
Key detection
I can't tell if this is necropost or not. I don't think it matters, because I'm closing this topic.“our server is scratch'ing its head” did you delete it or something i kinda made it but a little bit weird
https://scratch.mit.edu/projects/992550669/
check this out
Last edited by DangerPuppy10 (Sept. 14, 2024 23:27:54)
웃
WORSHIP RUBBER DUCK!!!!
I shall
I live in the suggestions sub-forum.
I might move into a 5-star forum!! I think it's called A“bout Scratch”?
YIPPEEEEEE
It would be greatly appreciated if you gave me an internet!
Workaround chart:
- Discussion Forums
- » Help with Scripts
- » Key detection