2 GUI programs, in general

A GUI (graphical user interface) program is called event-driven. This means that a GUI is constantly “stuck” in an infinite loop waiting for something to happen. When “something happens”, a GUI program responses accordingly.

For example, when a GUI word processor is active, it is actually not doing anything at all most of the time. Instead, it waits for something, also known as an event, to happen. For a word processor, the most common event is a “key press’ event.

When a user presses a key, the hardware (including the keyboard, USB controller, the South bridge of the chip set) generates a hardware event. This hardware event is intercepted by the operating system (such as Windows or Linux). The operating system then proceeds to interpret the hardware event and create a software event for the application program that has the “focus”.

This software event ends the word processor’s wait. After all, the word processing is waiting for an event. As the word processor receives the event, it has to distinguish it from all the other events that it may process. Once the event is identified as a “keypress” event, the word processor executes the “keypress’ event handler.

The “keypress” event handler will trigger some complex logic. It may add a character to the document being edited, and may cause many page numbers to change.

After the word processor does what it needs to process the keypress event, it returns to sleep and wait for another event.

Note that although most events are triggered by some sort of user action (e.g., moving a mouse, clicking a mouse button, pressing a key), some events can originate from the computer itself. Such events include timer events and network events. Timer events are very useful. For example, if you configure a word processor to automatically save a document every 15 minutes, a timer event may trigger the autosave mechanism.