Events: programs reacting to action — Computing, 11–13 years
An event is something that happens, such as a click, key press or sensor reading, and lets a program respond when it happens.
Waiting for something to happen
An event is a signal that something has happened: a player clicks, a key is pressed, or a temperature changes. Instead of running one long list from start to finish, a program waits and runs the right response for each signal. This makes interactive software possible.
Why events were needed
A program that only follows a fixed sequence cannot know when a person will click or when a sensor will detect movement. Early interactive tools needed a way to connect an unpredictable happening with a planned response. Events solve that timing problem without guessing when the happening will occur.
A button that counts
Start clicks at 0. Set the button’s event to “when clicked”: add 1 to clicks, then show clicks. The first click changes 0 to 1; the second changes 1 to 2; the third changes 2 to 3. The program does not need to know the times in advance.
One event is not every event
A program may respond to a click but ignore a key press, because each response is attached to a particular event. That can feel surprising when both actions seem like “input”. Check the event name carefully: the right instructions will run only when that exact kind of signal arrives.
Events all around us
Games use events for jumping when a key is pressed, and websites use them for opening a menu after a tap. A smartwatch can react to a sensor event by counting steps or warning about a high pulse. In each case, the response waits for a signal from a person or device.
Keep exploring
Other languages
Loading MyLeoNes™…