Today you will use key-pressed as a live Boolean condition, not just an event trigger.
1 Warm-Up
2 Predict
3 Try It
4 Plan
5 Build
6 Fix It
7 Extend
8 Math Challenge
For teachers · goals · guide
Lesson Outcomes · for teachersCSTA 2
✦ CSTA 2-AP-12 · CSTA 2-AP-17 · ISTE 1.5.c · Standards
| 🎯 I can | use key-pressed as a live Boolean condition, not just an event trigger |
| 📝 New words | 7 words |
| ⏱ Lesson time | ~40 min |
Teacher Guide
📋 Before class
⚠️ Common misconceptions
- Students often believe when key pressed and if
do the same thing. The critical difference: when key pressed fires once per keydown event, while if inside forever is checked every frame — enabling smooth, held-key movement. - Students may think two keys cannot be true simultaneously. They can — polling inside one forever loop detects both at the same frame.
🎯 Differentiation
🐢 Struggling: Build the two versions side by side (event vs. polling) and have students hold the key for 3 seconds. The difference in smoothness is immediately felt.
🚀 Advanced: Challenge students to add acceleration: instead of a fixed step size, use a velocity variable that increases while a key is held and decreases when released.
💡 During the lesson
- Warm-UpAsk: "When you hold a movement key in a game, does the character move smoothly or in jerks?" Choppy = the game reacts only to taps. Smooth = the game keeps checking while you hold. Students have felt both without knowing the cause. The block that keeps checking is a condition ❓ — a Boolean ✅ test that is only ever true or false.
- Try ItRun Approach A live — hold the key and observe the stutter. Then run Approach B — hold the key and feel the difference. Ask: "Why does Approach A stutter?" (OS key-repeat delay.) "Why does B feel smooth?" (Checked every frame, not waiting for OS events.)
Diagonal movement (holding two keys) is a key insight. Both if blocks run in the same frame, so both x and y change simultaneously. Ask: "How many if blocks fire in one frame if you hold right and up?" (Two — both conditions are true.) - PlanAsk students: "Why use 4 separate if blocks instead of if-else?" (If-else would prevent diagonal movement — only one branch runs per frame. Separate ifs allow multiple to run together.)
- BuildStep 7 introduces nested if blocks for a modifier key. This previews the concept of key combinations. In step 10 every student abstracts the step size into a reusable variable.
Show the picture first. Ask what will happen — everyone points or says one word.
Everyone picks an answer first. Then press the flag together.
Change one thing at a time. Run it, watch, then change the next thing.
Pairs put the cards in order before anyone opens Scratch.
Students build step by step. Walk around — help with questions, not with the mouse.
Ask: what did we want, and what did it do? Let them find it.
Fast finishers pick the next tier. Everyone else finishes their build.
Work it out on paper first. Then check it on the stage.