When Key Pressed/Released Blocks
-
Prerequisite
Description
The “When () Key Pressed” and “When () Key Released” blocks are Hat Blocks in the Events category.
The When () Key Pressed Block
This block plays the blocks attached below it when the selected key is pressed down on the keyboard.
The When () Key Released Block
This block plays the blocks attached below it when the selected key is released (let go) on the keyboard.
How to Select Different Keys?
To select a different key, click on the drop-down menu of the block, and then select any key from the Keyboard Pop-up.
What Happens When We Keep a Key Pressed Down?
If you keep holding a key down, the “When ()Key Pressed” block will be played again and again, as if you are pressing down the key repeatedly.
Demo: Dance Animation with Key Pressed/Released
Here is how you can use the “When Key Pressed” and “When Key Released” blocks together to start and stop a sprite’s dancing animation.