انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Block: home
0. Lab tour1
1. Getting started5
2. Motion5
3. Looks and sound5
4. Events4
5. Loops5
6. Conditions and sensing4
7. Variables and randomness4
8. Project: the “Catch Robo” game3
9. Messages: characters talk to each other4
10. Clones: one character, many copies4
11. My Blocks: make a new block3
12. Operators and time4
13. The pro project: a jumping game4

Keyboard keys

Section 4: EventsLesson 4.2 · ⏱ 7 min

The block when key pressed runs the blocks under it when a certain key is pressed. With four scripts for the four arrows you control the character like in games.

🧩 Right arrow
Blocks: when (right arrow) key pressed, change x by (10)
🧩 Left arrow
Blocks: when (left arrow) key pressed, change x by (-10)
🖥️ What happens on the stage?
When you press the right arrow Robo moves right, and when you press the left arrow he moves left.

📌 Another example: a car that turns

The right and left arrows turn Robo 15 degrees, and the up arrow moves him forward in his direction.

Blocks: when 🚩 clicked, go to x: (0) y: (0), point in direction (90)
Blocks: when (right arrow) key pressed, turn ↻ (15) degrees
Blocks: when (left arrow) key pressed, turn ↺ (15) degrees
Blocks: when (up arrow) key pressed, move (10) steps
He turned, then moved
He turned, then moved
✍️ Practise
Finish the other two arrows (up arrow and down arrow) using change y.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

The space key makes Robo say “Jump!” and jump up 40, then come down.

👀 Show the solution
Blocks: when (space) key pressed, say (Jump!) for (1) seconds, change y by (40), wait (0.3) seconds, change y by (-40)
The result on the stage
The result on the stage
Medium

The key a makes Robo 10 bigger, and the key d makes him 10 smaller. We pressed a three times, then d: what is the size?

👀 Show the solution
Blocks: when 🚩 clicked, set size to (100) %
Blocks: when (a) key pressed, change size by (10)
Blocks: when (d) key pressed, change size by (-10)
The size is 120
The size is 120
Hard

The four arrows: each arrow points Robo its way (point in direction), then moves him 10.

👀 Show the solution
Blocks: when 🚩 clicked, go to x: (0) y: (0)
Blocks: when (right arrow) key pressed, point in direction (90), move (10) steps
Blocks: when (left arrow) key pressed, point in direction (-90), move (10) steps
Blocks: when (up arrow) key pressed, point in direction (0), move (10) steps
Blocks: when (down arrow) key pressed, point in direction (180), move (10) steps
Three to the right and two up
Three to the right and two up
Finished the lesson? Mark it so your progress counts.