Algorithmic Solutions > LEDA > LEDA Guide > Windows and Panels > Events


What is an Event?

In window systems the communication between input devices such as mouse or keyboard and application programs is realized by so-called events.
  • If the mouse pointer is moved across the window, the system generates motion events that can be used by an application program to keep track of the current position of the mouse pointer.
  • If a mouse button is clicked, an event is generated that carries the information which button was pressed at what position.
  • If a key is pressed, a keyboard event is triggered that tells the application program which key was pressed and what window had the input focus.

The Event Queue

Events are buffered in an event queue such that applications can access them in a similar way as character input of a C++ stream. It is possible to read and remove the next event from the queue and to push events back into the queue.

The LEDA Events

LEDA supports only the following restricted set of events. Each event is represented by a five-tuple (type,window,value,position,time stamp).
  • type: an integer from the enumeration enum {button_press_event, button_release_event, key_press_event,key_release_event, motion_event, configure_event, no_event}
  • window: window to which the event refers. Usually the window under the mouse pointer.
  • value: integer whose interpretation depends on the type of the event
  • position: position of the mouse pointer in the user coordinate system at the time the event occurred
  • time stamp: time of global system clock at which event occurred counted in milliseconds.

Blocking Events

The operation

  int W.read_event(int& val, double& x, 
                   double& y, unsigned long& t);

removes the first event from the event queue. If the event queue is empty, the program waits until a new event occurs. This operation is similar to the read_mouse() input operation.

On the right you see a screenshot of the example for blocking events.

Picture of Convex Hull

Example for Blocking Events

The operation

  int W.read_event(int& val, double& x, double& y,
                   unsigned long& t, int timeout);

waits for at most timeout milliseconds if no event is available.

Putting Back Events

The global function
  void put_back_event();
puts the event handled last back to the event queue such that it will be processed by the next read_event() or read_mouse() or basic input operation. This operation is useful in programs that have to handle different types of input objects using the basic input operations.

On the right you see a screenshot of the example for putting back events.

Picture of Convex Hull

Non-Blocking Events

The function
  int W.get_event(int& val, double& x, double& y);
is a non-blocking variant of W.read_event(). There is also a more general non-member variant that allows to read events of arbritrary windows
  int read_event(<window*& wp, int& val, double& x, double& y);

Example for Non-Blocking Events

See also:

Windows and Panels

Pixel and User Coordinate System

Mouse Input

Input and Output Operators

Drawing Operations

Basic Data Types for 2D Geometry

Manual Pages:

Manual Page Windows

Please send any suggestions, comments or questions to
© Copyright 2001-2003, Algorithmic Solutions Software GmbH