Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Holding a key
- cs646524
-
2 posts
Holding a key
I want to make a project that requires the player to repeatedly tap a key. However, holding down the key can allow the player to cheat because the code just keeps on looping as long as the player holds down the key! How do I make the code only play once each time the player taps a key?

- mstone326
-
1000+ posts
Holding a key
Put a wait until not key (whatever) key pressed. That will require the player to release the key and then press it again.
- Th3_C0d3r
-
100+ posts
Holding a key
Use could use something like this…
-Scratch On!
when green flag clicked
forever
if <key [space v] pressed?> then//Wait until key is press
Do something//Do what you want ONCE
wait until <not <key [space v] pressed?>>//Wait until key is no longer held down
end
end
-Scratch On!
- learncsscratch
-
100+ posts
Holding a key
You can also make it so they have to go back and forth between two keys…this can be fun for racing games and stuff…
For example:
For example:
wait until <key [a v] pressed?>
move (5) steps
wait until <key [b v] pressed?>
move (5) steps
- Programmer_55
-
51 posts
Holding a key
Try this:
when [... v] key pressed
...
wait until <not <key [... v] pressed?>>
- cutekitten5678
-
52 posts
Holding a key
when green flag clicked
forever
if <<touching [key sprite v] ?> and <key [(put your chosen key here) v] pressed?>> then
go to [player sprite v]
end
end
- Galatic-Man
-
4 posts
Holding a key
thank you! Use could use something like this…when green flag clicked
forever
if <key [space v] pressed?> then//Wait until key is press
Do something//Do what you want ONCE
wait until <not <key [space v] pressed?>>//Wait until key is no longer held down
end
end
-Scratch On!
- Discussion Forums
- » Help with Scripts
-
» Holding a key