Eng:When () Key Pressed (block)

The When Key Pressed block is an Events block and a Hat block. Scripts placed underneath this block will activate when the specified key is pressed.

The keys that can be sensed with this block include the entire English alphabet ( a b c etc.), the number keys ( 0 1 2 etc.), the arrow keys ( left up right down ), and the space key. After an update, this block now includes an any option, which allows one to press any key to operate the block.

In the Experimental Viewer, the enter key (or return key on Macs) could also be sensed.

The block will act similarly to typing text in a text box. There will be a delay between when the block first executes and the second time, but after that, there will be no delay until the key is released.

Example Uses
This block is used to get input from the player, for a variety of uses.

Some common uses include:


 * Controlling an object

when [space v] key pressed broadcast [Fire! v] repeat (5) change y by (5)


 * Typing on a word processor

when [a v] key pressed switch to costume [a v] stamp change x by (20)


 * Starting animations

when [space v] key pressed broadcast [Animation starts! v] play sound [Intro v]


 * Moving around a map

when [up arrow v] key pressed change y by (15)

Workaround
This block can be partially replicated with the following code:

when flag clicked forever if  . . . end

A more precise workaround:

when gf clicked forever if  then broadcast [ready v]

when I receive [ready v] .. .