← Years 5–6 Creating Digital Solutions

Event block: when key pressed

An event block that waits for a key to be pressed. Each time you press the key you chose, the blocks stacked under it run. You can pick a different key from the drop-down list.

Understanding Event block: when key pressed in Years 5–6 Creating Digital Solutions

What it does: Two separate event blocks, each with its own key, let one program respond to different keys in different ways. The say block is stacked under the event block, so it runs each time the space key is pressed. The key is chosen from the drop-down list on the event block. You do not type it in. The script runs once for each key press, so pressing the key 3 times runs it 3 times. The event block must be at the top of the stack. Blocks placed above it will not be started by the key press.

Common mistakes: Line 3 uses the left arrow key again, so both scripts run on the left arrow and the right arrow does nothing. It should be 'when right arrow key pressed'. Direction 270 faces left, but this script runs when the right arrow key is pressed. It should be 'point in direction 90'.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 41–50) and word search (Modules 41–74).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which block starts a script each time the space key is pressed?
when space key pressedwhen green flag clicked
Matches
say Hello! for 2 seconds when space key pressed
↓
The event block is at the bottom. It must be on top so the blocks stacked under it run when the key is pressed.
Applying
Meanings
Term
when space key pressed
Meaning
An event block that waits for a key to be pressed. Each time you press the key you chose, the blocks stacked under it run. You can pick a different key from the drop-down list.
Practice
when space key pressed
Testing
Gaps
space key pressed
Check Answer
Spots
2change x by -10
3when left arrow key pressed

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Ermine' badge — Tundra Streak, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which block starts a script each time the space key is pressed?
A. when space key pressed ✓
B. when green flag clicked
'when space key pressed' is the event block that waits for the space key. The green flag block waits for a click on the flag instead.
2. You want a script to run when the player presses the up arrow. What do you do?
A. Choose 'up arrow' from the drop-down list on the block ✓
B. Type the word 'up' under the block
The key is chosen from the drop-down list on the event block. You do not type it in.
3. True or false: the blocks under 'when space key pressed' run every time you press the space key.
A. True ✓
B. False
The script runs once for each key press, so pressing the key 3 times runs it 3 times.
4. Which script will run when you press the space key?
A. move 10 steps, then when space key pressed
B. when space key pressed, then move 10 steps ✓
The event block must be at the top of the stack. Blocks placed above it will not be started by the key press.
5. A sprite should jump when the 'a' key is pressed, but nothing happens when you press 'a'. What is the most likely mistake?
A. The sprite has too many blocks
B. The block is still set to 'space' instead of 'a' ✓
Check the drop-down list. The event block only reacts to the key that is chosen on it.

Match the Pairs

when space key pressed → Runs the blocks stacked under it each time the space key is pressed
when up arrow key pressed → Starts its script when the up arrow key is pressed, because that key was chosen in the drop-down list
You can have several event scripts in one program, each reacting to a different key → when left arrow key pressed when right arrow key pressed
The blocks stacked under the event block run every time the key is pressed → when space key pressed say Jump! for 1 seconds
say Hello! for 2 seconds when space key pressed → The event block is at the bottom. It must be on top so the blocks stacked under it run when the key is pressed.
when space key pressed when space key pressed → Both scripts use the same key, so they both start at once. To make different things happen, choose a different key for each event block.

Key Term

when space key pressed
An event block that waits for a key to be pressed. Each time you press the key you chose, the blocks stacked under it run. You can pick a different key from the drop-down list.

Fill in the Blanks

1. when space key pressed move (10) steps
Hint: Type the word that starts every event block.
2. when space key pressed move (10) steps
Hint: Type the name of the long key at the bottom of the keyboard that starts this script.
3. when space key pressed turn (15) degrees
Hint: Type the word that says what happens to the key to start the script.
4. when up arrow key pressed change y by 10 when down arrow key pressed
Hint: A second event script needs its own key. Type the direction that is the opposite of up.
5. when space key pressed move (10) steps
Hint: Type the motion block name that runs each time the key is pressed.

Spot the Error

Question 1
A when left arrow key pressed
B change x by -10
C when left arrow key pressed
D change x by 10
Line C — Line 3 uses the left arrow key again, so both scripts run on the left arrow and the right arrow does nothing. It should be 'when right arrow key pressed'.
Question 2
A when right arrow key pressed
B point in direction 270
C move 10 steps
Line B — Direction 270 faces left, but this script runs when the right arrow key is pressed. It should be 'point in direction 90'.
Question 3
A when space key pressed
B say Boing! for 1 seconds
C up arrow key pressed
D change y by 10
Line C — Line 3 is missing 'when', so it is not an event block. The second script would never start. It should be 'when up arrow key pressed'.
Question 4
A when space key pressed
B when up arrow key pressed
C say Zoom! for 1 seconds
Line B — An event block starts a script, so it cannot sit under another event block. This extra event block splits the script, and the blocks below it would not run on the space key. Line 2 should be 'move 10 steps'.
Question 5
A when h key pressed
B say Hi! for 2 seconds
C when b key pressed
D say Hi! for 2 seconds
Line D — The script for the b key should say goodbye, but line 4 says Hi! again. It should be 'say Bye! for 2 seconds'.

Student with a class code? Join your class →