Event block: when key pressed

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Event block: when key pressed

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which block starts a script each time the space key is pressed?
A when space key pressed
B when green flag clicked
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
3. True or false: the blocks under 'when space key pressed' run every time you press the space key.
A True
B False
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
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'

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

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

Definitions

when space key pressed

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
____ space key pressed move (10) steps
2.
when _____ key pressed move (10) steps
3.
when space key _______ turn (15) degrees
4.
when up arrow key pressed change y by 10 when ____ arrow key pressed
5.
when space key pressed ____ (10) steps

Spot the Error

Shade in the letter of the line that contains an 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
Question 2
A when right arrow key pressed
B point in direction 270
C move 10 steps
Question 3
A when space key pressed
B say Boing! for 1 seconds
C up arrow key pressed
D change y by 10
Question 4
A when space key pressed
B when up arrow key pressed
C say Zoom! for 1 seconds
Question 5
A when h key pressed
B say Hi! for 2 seconds
C when b key pressed
D say Hi! for 2 seconds

Answer Key

Event block: when key pressed
Section A: Quick Questions
Q1
A — when space key pressed
Q2
A — Choose 'up arrow' from the drop-down list on the block
Q3
A — True
Q4
B — when space key pressed, then move 10 steps
Q5
B — The block is still set to 'space' instead of 'a'
Section B: Match the Pairs
Q1
when space key pressed → Runs the blocks stacked under it each time the space key is pressed
Q2
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
Q3
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
Q4
The blocks stacked under the event block run every time the key is pressed → when space key pressed say Jump! for 1 seconds
Q5
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.
Q6
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.
Section C: Definitions
Q1
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.
Section D: Fill in the Blanks
Q1
when space key pressed move (10) steps
Q2
when space key pressed move (10) steps
Q3
when space key pressed turn (15) degrees
Q4
when up arrow key pressed change y by 10 when down arrow key pressed
Q5
when space key pressed move (10) steps
Section E: Spot the Error
Q1
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'.
Q2
B — Direction 270 faces left, but this script runs when the right arrow key is pressed. It should be 'point in direction 90'.
Q3
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'.
Q4
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'.
Q5
D — The script for the b key should say goodbye, but line 4 says Hi! again. It should be 'say Bye! for 2 seconds'.