LightMySky
En anglais

Events: Programs That React to What the User Does

A program does not have to run from top to bottom. A handler sits waiting for a click, a key press or a collision, and runs only when that thing happens.

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • Attach one handler to a key press and another to a click in the same program, and say which runs when
  • Explain why an event-driven program looks like it is doing nothing until the user acts
  • Fix a program where the handler was attached to the wrong object or the wrong event

1 · Read

Some programs do not run from top to bottom. A handler is a small set of instructions that sits waiting for one event, like a click or a key press. It runs only when that event happens.

Try it together

Imagine a game where the left arrow moves your sprite and a click changes its colour. Pressing the key runs the key handler, and clicking runs the click handler. Tapping a button on a page can run code that changes its colour, which tells you it was clicked.

That is why an event program looks like it is doing nothing. It is not stuck. It is listening, and nothing moves until you act.

When the wrong thing happens, check the object first. A click handler on the Stop button never runs when you click Play.

Then check the event. A handler tied to a key press runs on keys, not clicks, so a sound meant for a click plays on a key instead.

A handler can also test before it acts. A Send button should check that the message box holds text, or it sends with nothing typed.

Handlers wait for their event, then run, so nothing happens until you click or press.

Practice items adapted from WeBWorK Open Problem Library problems by University of Missouri contributors (CC BY-NC-SA 3.0). Readings written for this dataset.

2 · Watch

En anglais

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Where this leads

Jobs that lean on this skill. Follow one to see everything it is built on.

Then practise

10 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Spotted a problem on this page? Tell us
Events: Programs That React to What the User Does · Computing, ages 12 to 13 · LightMySky