---
title: "Events: Programs That React to What the User Does"
description: "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."
canonical: https://lightmysky.com/learn/computing/events-programs-that-react-to-what-the-user-does-mt_HFtGUhZHz4
source: https://lightmysky.com/learn/computing/events-programs-that-react-to-what-the-user-does-mt_HFtGUhZHz4.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# 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.

Subject: Computing · Area: Computing Fundamentals · Ages 12 to 13
Page: https://lightmysky.com/learn/computing/events-programs-that-react-to-what-the-user-does-mt_HFtGUhZHz4

## Ready when they can

- 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

## Lesson: Programs that wait for you

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.

**Example.** 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.

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

## Practice

10 questions on this page, each with its working shown.

## Needs first

- [Programming with Loops and Variables](https://lightmysky.com/learn/computing/programming-with-loops-and-variables-mt_9x5zgShXPg)

## Optional connections

- [AI in Computer Games](https://lightmysky.com/learn/computing/ai-in-computer-games-mt_fT4G0QloX5)

## Opens up

- [Conditions That Combine: And, Or and Not](https://lightmysky.com/learn/computing/conditions-that-combine-and-or-and-not-mt_ZYdtXQZy5r)
