ALLEGRO_EVENT(3)
๐ NAME ๐
ALLEGRO_EVENT โ Allegro 5 API. Yep bestie, this is the ALLEGRO_EVENT(3) page from the Library Functions Manual, and itโs lowkey a whole iconic little union โจ.
๐ฆ SYNOPSIS ๐ฆ
#include <allegro5/allegro.h>
typedef union ALLEGRO_EVENT ALLEGRO_EVENT;
โจ DESCRIPTION โจ
okay so an ALLEGRO_EVENT is literally a union of all builtin event structures, i.e. it is an object large enough to hold the data of any event type. slay. all events have these fields in common:
type(ALLEGRO_EVENT_TYPE) โ Indicates the type of event.any.source(ALLEGRO_EVENT_SOURCE *) โ The event source which generated the event.any.timestamp(double) โ When the event was generated.
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(3). periodt ๐
.
Each event is of one of the following types, with the usable fields given. buckle up ๐.
๐ฎ ALLEGRO_EVENT_JOYSTICK_AXIS ๐ฎ
A joystick axis value changed.
joystick.id(ALLEGRO_JOYSTICK *) โ The joystick which generated the event. This is not the same as the event sourcejoystick.source. iykyk.joystick.stick(int) โ The stick number, counting from zero. Axes on a joystick are grouped into โsticksโ.joystick.axis(int) โ The axis number on the stick, counting from zero.joystick.pos(float) โ The axis position, from-1.0to+1.0.
๐น๏ธ ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN ๐น๏ธ
A joystick button was pressed.
joystick.id(ALLEGRO_JOYSTICK *) โ The joystick which generated the event.joystick.button(int) โ The button which was pressed, counting from zero.
๐น๏ธ ALLEGRO_EVENT_JOYSTICK_BUTTON_UP ๐น๏ธ
A joystick button was released.
joystick.id(ALLEGRO_JOYSTICK *) โ The joystick which generated the event.joystick.button(int) โ The button which was released, counting from zero.
๐ง ALLEGRO_EVENT_JOYSTICK_CONFIGURATION ๐ง
A joystick was plugged in or unplugged. See al_reconfigure_joysticks(3) for details.
โจ๏ธ ALLEGRO_EVENT_KEY_DOWN โจ๏ธ
A keyboard key was pressed.
keyboard.keycode(int) โ The code corresponding to the physical key which was pressed. See the [Key codes] section for the list ofALLEGRO_KEY_*constants.keyboard.display(ALLEGRO_DISPLAY *) โ The display which had keyboard focus when the event occurred.
Note: this event is about the physical keys being pressed on the keyboard. Look for ALLEGRO_EVENT_KEY_CHAR events for character input.
โจ๏ธ ALLEGRO_EVENT_KEY_UP โจ๏ธ
A keyboard key was released.
keyboard.keycode(int) โ The code corresponding to the physical key which was released. See the [Key codes] section for the list ofALLEGRO_KEY_*constants.keyboard.display(ALLEGRO_DISPLAY *) โ The display which had keyboard focus when the event occurred.
๐ฌ ALLEGRO_EVENT_KEY_CHAR ๐ฌ
A character was typed on the keyboard, or a character was auto-repeated.
keyboard.keycode(int) โ The code corresponding to the physical key which was last pressed. See the [Key codes] section for the list ofALLEGRO_KEY_*constants.keyboard.unichar(int) โ A Unicode code point (character). This may be zero or negative if the event was generated for a non-visible โcharacterโ, such as an arrow or Function key. In that case you can act upon thekeycodefield.
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.
keyboard.modifiers(unsigned) โ This is a bitfield of the modifier keys which were pressed when the event occurred. See โKeyboard modifier flagsโ for the constants.keyboard.repeat(bool) โ Indicates if this is a repeated character.keyboard.display(ALLEGRO_DISPLAY *) โ The display which had keyboard focus when the event occurred.
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.
๐ฑ๏ธ ALLEGRO_EVENT_MOUSE_AXES ๐ฑ๏ธ
One or more mouse axis values changed.
mouse.x(int) โ x-coordinatemouse.y(int) โ y-coordinatemouse.z(int) โ z-coordinate. This usually means the vertical axis of a mouse wheel, where up is positive and down is negative.mouse.w(int) โ w-coordinate. This usually means the horizontal axis of a mouse wheel.mouse.dx(int) โ Change in the x-coordinate value since the previousALLEGRO_EVENT_MOUSE_AXESevent.mouse.dy(int) โ Change in the y-coordinate value since the previousALLEGRO_EVENT_MOUSE_AXESevent.mouse.dz(int) โ Change in the z-coordinate value since the previousALLEGRO_EVENT_MOUSE_AXESevent.mouse.dw(int) โ Change in the w-coordinate value since the previousALLEGRO_EVENT_MOUSE_AXESevent.mouse.pressure(float) โ Pressure, ranging from0.0to1.0.mouse.display(ALLEGRO_DISPLAY *) โ The display which had mouse focus.
Note: Callingal_set_mouse_xy(3)also will result in a change of axis values, but such a change is reported withALLEGRO_EVENT_MOUSE_WARPED(3)events instead which are identical except for their type.
Note: currentlymouse.displaymay beNULLif an event is generated in response toal_set_mouse_axis(3).
๐ฑ๏ธ ALLEGRO_EVENT_MOUSE_BUTTON_DOWN ๐ฑ๏ธ
A mouse button was pressed.
mouse.x(int) โ x-coordinatemouse.y(int) โ y-coordinatemouse.z(int) โ z-coordinatemouse.w(int) โ w-coordinatemouse.button(unsigned) โ The mouse button which was pressed, numbering from 1. As a convenience, the constantsALLEGRO_MOUSE_BUTTON_LEFT,ALLEGRO_MOUSE_BUTTON_RIGHT,ALLEGRO_MOUSE_BUTTON_MIDDLEare provided. However, depending on the hardware there may be more or fewer mouse buttons. You can checkal_get_mouse_num_buttons(3)if you want to be sure.mouse.pressure(float) โ Pressure, ranging from0.0to1.0.mouse.display(ALLEGRO_DISPLAY *) โ The display which had mouse focus.
๐ฑ๏ธ ALLEGRO_EVENT_MOUSE_BUTTON_UP ๐ฑ๏ธ
A mouse button was released.
mouse.x(int) โ x-coordinatemouse.y(int) โ y-coordinatemouse.z(int) โ z-coordinatemouse.w(int) โ w-coordinatemouse.button(unsigned) โ The mouse button which was released, numbering from 1. As a convenience, the constantsALLEGRO_MOUSE_BUTTON_LEFT,ALLEGRO_MOUSE_BUTTON_RIGHT,ALLEGRO_MOUSE_BUTTON_MIDDLEare provided. However, depending on the hardware there may be more or fewer mouse buttons. You can checkal_get_mouse_num_buttons(3)if you want to be sure.mouse.pressure(float) โ Pressure, ranging from0.0to1.0.mouse.display(ALLEGRO_DISPLAY *) โ The display which had mouse focus.
๐ ALLEGRO_EVENT_MOUSE_WARPED ๐
al_set_mouse_xy(3) was called to move the mouse. This event is identical to ALLEGRO_EVENT_MOUSE_AXES otherwise.
๐ญ ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY ๐ญ
The mouse cursor entered a window opened by the program.
mouse.x(int) โ x-coordinatemouse.y(int) โ y-coordinatemouse.z(int) โ z-coordinatemouse.w(int) โ w-coordinatemouse.display(ALLEGRO_DISPLAY *) โ The display which had mouse focus.
๐ญ ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY ๐ญ
The mouse cursor left the boundaries of a window opened by the program.
mouse.x(int) โ x-coordinatemouse.y(int) โ y-coordinatemouse.z(int) โ z-coordinatemouse.w(int) โ w-coordinatemouse.display(ALLEGRO_DISPLAY *) โ The display which had mouse focus.
๐ฑ ALLEGRO_EVENT_TOUCH_BEGIN ๐ฑ
The touch input device registered a new touch.
touch.display(ALLEGRO_DISPLAY) โ The display which was touched.touch.id(int) โ An identifier for this touch. If supported by the device it will stay the same for events from the same finger until the touch ends.touch.x(float) โ The x coordinate of the touch in pixels.touch.y(float) โ The y coordinate of the touch in pixels.touch.dx(float) โ Movement speed in pixels in x direction.touch.dy(float) โ Movement speed in pixels in y direction.touch.primary(bool) โ Whether this is the only/first touch or an additional touch.
๐ SINCE ๐
5.1.0
๐ ALLEGRO_EVENT_TOUCH_END ๐
A touch ended.
Has the same fields as ALLEGRO_EVENT_TOUCH_BEGIN(3).
๐ SINCE ๐
5.1.0
๐ซถ ALLEGRO_EVENT_TOUCH_MOVE ๐ซถ
The position of a touch changed.
Has the same fields as ALLEGRO_EVENT_TOUCH_BEGIN(3).
๐ SINCE ๐
5.1.0
๐ ALLEGRO_EVENT_TOUCH_CANCEL ๐
A touch was cancelled. This is device specific but could for example mean that a finger moved off the border of the device or moved so fast that it could not be tracked any longer.
Has the same fields as ALLEGRO_EVENT_TOUCH_BEGIN(3).
โจ SINCE โจ
5.1.0
๐ ALLEGRO_EVENT_TIMER
A ALLEGRO_TIMER(3) counter just went up by one โ thatโs the whole vibe.
timer.source(ALLEGRO_TIMER *) โ the timer that generated the event.timer.count(int64_t) โ the timer count value.
๐ช ALLEGRO_EVENT_DISPLAY_EXPOSE
The display (or a little rectangle of it) has become visible again.
display.source(ALLEGRO_DISPLAY *) โ the display that was exposed.display.x(int) โ the X position of the top-left corner of the rectangle that was exposed.display.y(int) โ the Y position of the top-left corner of the rectangle that was exposed.display.width(int) โ the width of the rectangle that was exposed.display.height(int) โ the height of the rectangle that was exposed.
Note: the display needs to be created with the ALLEGRO_GENERATE_EXPOSE_EVENTS flag for these events to be generated. No flag, no expose events, bestie.
๐ ALLEGRO_EVENT_DISPLAY_RESIZE
The window got resized. Iconic, honestly.
display.source(ALLEGRO_DISPLAY *) โ the display that was resized.display.x(int) โ the X position of the top-left corner of the display.display.y(int) โ the Y position of the top-left corner of the display.display.width(int) โ the new width of the display.display.height(int) โ the new height of the display.
You should normally respond to these events by calling al_acknowledge_resize(3). But heads up: further resize events may be generated by the time you process the event, so these fields may hold outdated information. Lowkey always check, fr fr.
โ ALLEGRO_EVENT_DISPLAY_CLOSE
The close button of the window has been pressed. The user said โbyeโ with their whole chest.
display.source(ALLEGRO_DISPLAY *) โ the display that was closed.
๐ซฅ ALLEGRO_EVENT_DISPLAY_LOST
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 the ALLEGRO_NO_PRESERVE_TEXTURE flag) and restore them when the device is โfoundโ (see ALLEGRO_EVENT_DISPLAY_FOUND(3)). However, this is not 100% fool proof (see discussion in al_create_bitmap(3)โs documentation).
Note: this event merely means that the display was lost, that is, DirectX suddenly lost the contents of all video bitmaps. In particular, you can keep calling drawing functions โ they just most likely wonโt do anything. If Allegroโs restoration of the bitmaps works well for you then no further action is required when you receive this event.
display.source(ALLEGRO_DISPLAY *) โ the display that was lost.
๐ ALLEGRO_EVENT_DISPLAY_FOUND
Generated when a lost device is restored to operating state. See ALLEGRO_EVENT_DISPLAY_LOST(3). Itโs giving โweโre so back.โ
display.source(ALLEGRO_DISPLAY *) โ the display that was found.
๐ช ALLEGRO_EVENT_DISPLAY_SWITCH_OUT
The window is no longer active, that is the user might have clicked into another window or โtabbedโ away. In response to this event you might want to call al_clear_keyboard_state(3) (possibly passing display.source as its argument) in order to prevent Allegroโs keyboard state from getting out of sync.
display.source(ALLEGRO_DISPLAY *) โ the display that was switched out of.
๐ช ALLEGRO_EVENT_DISPLAY_SWITCH_IN
The window is the active one again. Main character energy restored.
display.source(ALLEGRO_DISPLAY *) โ the display that was switched into.
๐ ALLEGRO_EVENT_DISPLAY_ORIENTATION
Generated when the rotation or orientation of a display changes. Very โthe phone did a little spinโ of it all.
display.source(ALLEGRO_DISPLAY *) โ the display that generated the event.event.display.orientationโ contains one of the following values:ALLEGRO_DISPLAY_ORIENTATION_0_DEGREESALLEGRO_DISPLAY_ORIENTATION_90_DEGREESALLEGRO_DISPLAY_ORIENTATION_180_DEGREESALLEGRO_DISPLAY_ORIENTATION_270_DEGREESALLEGRO_DISPLAY_ORIENTATION_FACE_UPALLEGRO_DISPLAY_ORIENTATION_FACE_DOWN
โธ๏ธ ALLEGRO_EVENT_DISPLAY_HALT_DRAWING
When a display receives this event it should stop doing any drawing and then call al_acknowledge_drawing_halt(3) immediately. Do not pass go, do not draw one more frame.
This is currently only relevant for Android and iOS. It will be sent when the application is switched to background mode, in addition to ALLEGRO_EVENT_DISPLAY_SWITCH_OUT(3). The latter may also be sent in situations where the application is not active but still should continue drawing, for example when a popup is displayed in front of it.
Note: this event means that the next time you call a drawing function, your program will crash. So you must stop drawing and you must immediately reply with al_acknowledge_drawing_halt(3). Allegro sends this event because it cannot handle this automatically. Your program might be doing the drawing in a different thread from the event handling, in which case the drawing thread needs to be signaled to stop drawing before acknowledging this event.
Note: mobile devices usually never quit an application, so to prevent the battery from draining while your application is halted it can be a good idea to callal_stop_timer(3)on all your timers, otherwise they will keep generating events. If you are using audio, you can also stop all audio voices (or passNULLtoal_set_default_voice(3)if you use the default mixer), otherwise Allegro will keep streaming silence to the voice even if the stream or mixer are stopped or detached.
SINCE 5.1.0
SEE ALSO ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING(3)
โถ๏ธ ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING
When a display receives this event, it may resume drawing again, and it must call al_acknowledge_drawing_resume(3) immediately. Back to business, bestie.
This is currently only relevant for Android and iOS. The event will be sent when an application returns from background mode and is allowed to draw to the display again, in addition to ALLEGRO_EVENT_DISPLAY_SWITCH_IN(3). The latter event may also be sent in a situation where the application is already active, for example when a popup in front of it closes.
Note: unlike ALLEGRO_EVENT_DISPLAY_FOUND(3) it is not necessary to reload any bitmaps when you receive this event.
SINCE 5.1.0
SEE ALSO ALLEGRO_EVENT_DISPLAY_HALT_DRAWING(3)
๐ ALLEGRO_EVENT_DISPLAY_CONNECTED
This event is sent when a physical display is connected to the device Allegro runs on. Currently, on most platforms, Allegro supports only a single physical display. However, on iOS, a secondary physical display is supported. Slay, extra screen.
display.source(ALLEGRO_DISPLAY *) โ the display that was connected.
SINCE 5.1.1
๐ ALLEGRO_EVENT_DISPLAY_DISCONNECTED
This event is sent when a physical display is disconnected from the device Allegro runs on. Currently, on most platforms, Allegro supports only a single physical display. However, on iOS, a secondary physical display is supported.
display.source(ALLEGRO_DISPLAY *) โ the display that was disconnected.
๐๏ธ ALLEGRO_EVENT_DROP
If a display is created with the ALLEGRO_DRAG_AND_DROP flag it will generate ALLEGRO_EVENT_DROP events when files or text are dropped over the display. Itโs literally drag-and-drop, but make it Allegro.
drop.x(int) โ X coordinate that something is being dragged to.drop.y(int) โ Y coordinate that something is being dragged to.drop.text(char *) โ the filename or text that was dropped - this will beNULLwhile the item is being dragged and only set at the final drop.
Note: if the text field is notNULLownership transfers to the event receiver and it must eventually be freed withal_free.
drop.is_file(bool) โ if text is notNULLwhether the text is a filename or just plain text.drop.row(int) โ if there is multiple files or multiple rows of text this will number them, starting with0.drop.is_complete(bool) โ indicates that this event will be the last one sent for the drag&drop action. Ifis_completeis set before receiving an event where text was notNULLit means the user aborted the drag&drop.
SINCE 5.2.9
Unstable API: this is an experimental feature and currently only works for the X11 backend. Handle with care, bestie. ๐
And thatโs the whole page, babes โ footer says Allegro reference manual and ALLEGRO_EVENT(3), so you know itโs official. Go forth and handle those events like the main character you are. ๐โจ
๐ฆ where this page comes from
- arch rolling: allegro 5.2.11.3-2 ยท Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms