Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (February 2016)
Reason: Not enough information

Without much work, when you hold a button, it can do things the button was set to do for a repeated amount of times. However, if you want to make the button be not held, but only pressed once at a time, you can use the scripting in this tutorial.

What To Do

Holding Script

This is the script which will allow holding, which you want to avoid:

when flag clicked
forever
if <key [... v] pressed?> then
next backdrop
end
end

If you use this one, you might go forward more than one backdrop before you release the key. You can also use this one:

when [... v] key pressed
next backdrop

That will make it a little better because there will be a tiny pause after a hat block, although holding will still work. This is why you do not want to use it in a platformer.

Non-Holding Script

This is the script which does not allow holding, which you will want to use.

when flag clicked
forever
wait until <key [... v] pressed>
next backdrop
wait until <not <key [... v] pressed?>>
end

This will make it sense the key, perform an action, and wait for the key to be released before checking again. You can also change the order to:

when flag clicked
forever
wait until <key [... v] pressed?>
wait until <not <key [... v] pressed?>>
next backdrop


If you use this code, you have to press the key, and the backdrop will not change until you release it.

Advanced Cases

Let's say you are making a platformer, this can be useful when you run into issues

when [... v] key pressed
forever
wait until <not <key [... v] pressed?>>
broadcast [... v]
stop [this script v]

and then you want to make this:

when I receive [... v]
next backdrop

Uses

A key tapping sensor could be useful for many things, such as announcement projects, or projects with only words. It's often important in these projects, that users don't skip through the information quickly, so this script could be useful. If one wants to create a platformer, the first code could be used to to create nice, smooth controls.