Events are messages which are sent to the owner process of the object when the user interacts with the object in some way. A simple case is the user pressing a button. An event is then delivered to the owner process of the button (the process that created the button). In the following example, the program creates a button object and enables the events click and enter. This example shows that events are enabled in the same way as objects are configured with options.
The process is now ready to receive click and enter events from the button. The events delivered are always five tuples and consist of:
There are two categories of events:
Generic events are the same for all types of objects. The following table shows a list of generic event types which the graphics server can send to
a process. For generic events, the
The following sub-sections explains the event types and what they are used for.
These events are generated when a mouse button is pressed or released inside the object frame of a window, or frame object type. The button events are not object specific (compare to click). The format of the buttonpress event is:
The mouse button number which was pressed is the first argument in the
These events are generated when the mouse pointer (cursor) enters or leaves an object.
The focus event tracks which object currently holds the keyboard focus. Only one object at a time can hold the keyboard focus. To have the keyboard focus means that all keypresses from the keyboard will be delivered to that object. The format of a focus event is:
The FocusFlag argument is either 1, which means that the object has gained keyboard focus, or 0, which means that the object has lost keyboard focus.
This event is generated by an object which receives text input from the user, like entry objects. It can also be generated by window objects. The format of a keypress event is:
The
The motion event is used to track the mouse position in a window. When the user moves the mouse pointer (cursor) to a new position a motion event is generated. The format of a motion event is:
The current x and y coordinates of the cursor are sent along in the
The click and doubleclick events are the object specific event types. Only some objects have these events and the
Events can be matched against the object identifier in the receive statement. The disadvantage of matching against identifiers is that the program must pass the object identifiers as arguments to the event loop.
Another solution is to name the objects using the
A third solution is to set the
A good way of learning how events work is to write a short demo program like the one shown below and test how different events work.