ALLEGRO_EVENT
Allegro 5 API
- Provided by: allegro5-doc (Version: 2:5.0.11-2)
- Source: allegro5
- Report a bug
Allegro 5 API
#include <allegro5/allegro.h>
typedef union ALLEGRO_EVENT ALLEGRO_EVENT;
An ALLEGRO_EVENT is a union of all builtin event structures, i.e. it is an object large enough to hold the data of any event type. All events have the following fields in common:
By examining the type field you can then access type-specific fields. The any.source field tells you which event source generated that particular event. The any.timestamp field tells you when the event was generated. The time is referenced to the same starting point as al_get_time(3alleg5).
Each event is of one of the following types, with the usable fields given.
A joystick axis value changed.
A joystick button was pressed.
A joystick button was released.
A joystick was plugged in or unplugged. See al_reconfigure_joysticks(3alleg5) for details.
A keyboard key was pressed.
Note: this event is about the physical keys being pressed on the keyboard. Look for ALLEGRO_EVENT_KEY_CHAR events for character input.
A keyboard key was released.
A character was typed on the keyboard, or a character was auto-repeated.
Some special keys will set the unichar field to their standard ASCII values: Tab=9, Return=13, Escape=27. In addition if you press the Control key together with A to Z the unichar field will have the values 1 to 26. For example Ctrl-A will set unichar to 1 and Ctrl-H will set it to 8.
As of Allegro 5.0.2 there are some inconsistencies in the treatment of Backspace (8 or 127) and Delete (127 or 0) keys on different platforms. These can be worked around by checking the keycode field.
Note: in many input methods, characters are not entered one-for-one with physical key presses. Multiple key presses can combine to generate a single character, e.g. apostrophe + e may produce 'é'. Fewer key presses can also generate more characters, e.g. macro sequences expanding to common phrases.
One or more mouse axis values changed.
Note: Calling al_set_mouse_xy(3alleg5) also will result in a change of axis values, but such a change is reported with ALLEGRO_EVENT_MOUSE_WARPED events instead.
Note: currently mouse.display may be NULL if an event is generated in response to al_set_mouse_axis(3alleg5).
A mouse button was pressed.
A mouse button was released.
al_set_mouse_xy(3alleg5) was called to move the mouse. This event is identical to ALLEGRO_EVENT_MOUSE_AXES otherwise.
The mouse cursor entered a window opened by the program.
The mouse cursor leave the boundaries of a window opened by the program.
A timer counter incremented.
The display (or a portion thereof) has become visible.
Note: The display needs to be created with ALLEGRO_GENERATE_EXPOSE_EVENTS flag for these events to be generated.
The window has been resized.
You should normally respond to these events by calling al_acknowledge_resize(3alleg5). Note that further resize events may be generated by the time you process the event, so these fields may hold outdated information.
The close button of the window has been pressed.
When using Direct3D, displays can enter a "lost" state. In that state, drawing calls are ignored, and upon entering the state, bitmap's pixel data can become undefined. Allegro does its best to preserve the correct contents of bitmaps (see ALLEGRO_NO_PRESERVE_TEXTURE) and restore them when the device is "found" (see ALLEGRO_EVENT_DISPLAY_FOUND). However, this is not 100% fool proof.
To ensure that all bitmap contents are restored accurately, one must take additional steps. The best procedure to follow if bitmap constancy is important to you is as follows: first, always have the ALLEGRO_NO_PRESERVE_TEXTURE flag set to true when creating bitmaps, as it incurs pointless overhead when using this method. Second, create a mechanism in your game for easily reloading all of your bitmaps -- for example, wrap them in a class or data structure and have a "bitmap manager" that can reload them back to the desired state. Then, when you receive an ALLEGRO_EVENT_DISPLAY_FOUND event, tell the bitmap manager (or whatever your mechanism is) to restore your bitmaps.
Generated when a lost device is restored to operating state. See ALLEGRO_EVENT_DISPLAY_LOST.
The window is no longer active, that is the user might have clicked into another window or "tabbed" away.
The window is the active one again.
Generated when the rotation or orientation of a display changes.
ALLEGRO_EVENT_SOURCE(3alleg5), ALLEGRO_EVENT_TYPE(3alleg5), ALLEGRO_USER_EVENT(3alleg5), ALLEGRO_GET_EVENT_TYPE(3alleg5)