- "Key Pressed" redirects here. For the hat block that senses when a key is pressed, see When () Key Pressed (block).
|Key () Pressed?|
The keys available to be used in this block include the entire English alphabet ( Experimental Viewer, the key could also be chosen. After an update, this block now includes an option, which allows one to press any key to operate the block.etc.), the number keys ( etc.), the arrow keys ( ), and the key. In the
As this block checks if a key is being pressed or not, it is useful for controlling objects, especially with One Sprite One Script Projects. If the project requires key input, this block can be used to serve as a replacement for the When () Key Pressed block. The Hat block cannot be used in the middle of a script.
Some common uses for the Key () Pressed? block:
- Controlling a character
forever if <key [down arrow v] pressed?> then change y by (-10) end if <key [up arrow v] pressed?> then change y by (10) end if <key [left arrow v] pressed?> then change x by (-10) end if <key [right arrow v] pressed?> then change x by (10) end
- Word processors
- Moving objects
- Changing slides in slideshows or changing what characters say
say [Hello!] wait until <key [any v] pressed?> wait until <not <key [any v] pressed?>> say [Welcome to my game!]
|Note:||This only works offline.|
The When () Key Pressed block, the counterpart to the Key () Pressed? block senses the scroll wheel as well as the up/down keys. Combining these two blocks, it is possible to sense when somebody is using the scroll wheel. The following script is one way of doing this.
when [up arrow v] key pressed if <not <key [up arrow v] pressed?>> then . . .
The action is done when the scroll wheel is scrolled up. If the key pressed blocks are changed to the down arrow, it will sense when it is scrolled down.
There are five somewhat popular suggestions related to this block:
- Add more keys
- Make a reporter block that says which keys are being pressed down
- Make this a Stage Monitor
- Allow variables to replace the drop down
Some Scratch Modifications have at least one of these.