---
name: "ALLEGRO_EVENT"
section: "3alleg5"
platform: "linux"
package: "allegro5-doc"
version: "2:5.2.10.1+dfsg-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/ALLEGRO_EVENT/3alleg5"
---

# ALLEGRO\_EVENT(3alleg5)

Allegro 5 API

## NAME

ALLEGRO\_EVENT - Allegro 5 API

## SYNOPSIS

-

  ```
  #include <allegro5/allegro.h>
  typedef union ALLEGRO_EVENT ALLEGRO_EVENT;
  ```

## DESCRIPTION

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:

- 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(3alleg5).

Each event is of one of the following types, with the usable fields given.

### 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 source `joystick.source`.

- 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.0 to +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(3alleg5) 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 of ALLEGRO\_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 of ALLEGRO\_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 of ALLEGRO\_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 the `keycode` field.

  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-coordinate

- mouse.y (int)

  y-coordinate

- mouse.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 previous ALLEGRO\_EVENT\_MOUSE\_AXES event.

- mouse.dy (int)

  Change in the y-coordinate value since the previous ALLEGRO\_EVENT\_MOUSE\_AXES event.

- mouse.dz (int)

  Change in the z-coordinate value since the previous ALLEGRO\_EVENT\_MOUSE\_AXES event.

- mouse.dw (int)

  Change in the w-coordinate value since the previous ALLEGRO\_EVENT\_MOUSE\_AXES event.

- mouse.pressure (float)

  Pressure, ranging from `0.0` to `1.0`.

- mouse.display (ALLEGRO\_DISPLAY \*)

  The display which had mouse focus.

  *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(3alleg5) events instead which are identical except for their type.

  *Note:* currently mouse.display may be NULL if an event is generated in response to al\_set\_mouse\_axis(3alleg5).

### ALLEGRO\_EVENT\_MOUSE\_BUTTON\_DOWN

A mouse button was pressed.

- mouse.x (int)

  x-coordinate

- mouse.y (int)

  y-coordinate

- mouse.z (int)

  z-coordinate

- mouse.w (int)

  w-coordinate

- mouse.button (unsigned)

  The mouse button which was pressed, numbering from 1. As a convenience, the constants ALLEGRO\_MOUSE\_BUTTON\_LEFT, ALLEGRO\_MOUSE\_BUTTON\_RIGHT, ALLEGRO\_MOUSE\_BUTTON\_MIDDLE are provided. However, depending on the hardware there may be more or fewer mouse buttons. You can check al\_get\_mouse\_num\_buttons(3alleg5) if you want to be sure.

- mouse.pressure (float)

  Pressure, ranging from `0.0` to `1.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-coordinate

- mouse.y (int)

  y-coordinate

- mouse.z (int)

  z-coordinate

- mouse.w (int)

  w-coordinate

- mouse.button (unsigned)

  The mouse button which was released, numbering from 1. As a convenience, the constants ALLEGRO\_MOUSE\_BUTTON\_LEFT, ALLEGRO\_MOUSE\_BUTTON\_RIGHT, ALLEGRO\_MOUSE\_BUTTON\_MIDDLE are provided. However, depending on the hardware there may be more or fewer mouse buttons. You can check al\_get\_mouse\_num\_buttons(3alleg5) if you want to be sure.

- mouse.pressure (float)

  Pressure, ranging from `0.0` to `1.0`.

- mouse.display (ALLEGRO\_DISPLAY \*)

  The display which had mouse focus.

### ALLEGRO\_EVENT\_MOUSE\_WARPED

al\_set\_mouse\_xy(3alleg5) 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-coordinate

- mouse.y (int)

  y-coordinate

- mouse.z (int)

  z-coordinate

- mouse.w (int)

  w-coordinate

- mouse.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-coordinate

- mouse.y (int)

  y-coordinate

- mouse.z (int)

  z-coordinate

- mouse.w (int)

  w-coordinate

- mouse.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(3alleg5).

## SINCE

5\.1.0

### ALLEGRO\_EVENT\_TOUCH\_MOVE

The position of a touch changed.

Has the same fields as ALLEGRO\_EVENT\_TOUCH\_BEGIN(3alleg5).

## 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(3alleg5).

## SINCE

5\.1.0

### ALLEGRO\_EVENT\_TIMER

A \[timer\]ALLEGRO\_TIMER(3alleg5) counter incremented.

- timer.source (ALLEGRO\_TIMER \*)

  The timer which generated the event.

- timer.count (int64\_t)

  The timer count value.

### ALLEGRO\_EVENT\_DISPLAY\_EXPOSE

The display (or a portion thereof) has become visible.

- display.source (ALLEGRO\_DISPLAY \*)

  The display which was exposed.

- display.x (int)

  The X position of the top-left corner of the rectangle which was exposed.

- display.y (int)

  The Y position of the top-left corner of the rectangle which was exposed.

- display.width (int)

  The width of the rectangle which was exposed.

- display.height (int)

  The height of the rectangle which was exposed.

  *Note:* The display needs to be created with ALLEGRO\_GENERATE\_EXPOSE\_EVENTS flag for these events to be generated.

### ALLEGRO\_EVENT\_DISPLAY\_RESIZE

The window has been resized.

- display.source (ALLEGRO\_DISPLAY \*)

  The display which 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(3alleg5). Note that further resize events may be generated by the time you process the event, so these fields may hold outdated information.

### ALLEGRO\_EVENT\_DISPLAY\_CLOSE

The close button of the window has been pressed.

- display.source (ALLEGRO\_DISPLAY \*)

  The display which 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(3alleg5)). However, this is not 100% fool proof (see discussion in al\_create\_bitmap(3alleg5)’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 which was lost.

### ALLEGRO\_EVENT\_DISPLAY\_FOUND

Generated when a lost device is restored to operating state. See ALLEGRO\_EVENT\_DISPLAY\_LOST(3alleg5).

- display.source (ALLEGRO\_DISPLAY \*)

  The display which 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(3alleg5) (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 which was switched out of.

### ALLEGRO\_EVENT\_DISPLAY\_SWITCH\_IN

The window is the active one again.

- display.source (ALLEGRO\_DISPLAY \*)

  The display which was switched into.

### ALLEGRO\_EVENT\_DISPLAY\_ORIENTATION

Generated when the rotation or orientation of a display changes.

- display.source (ALLEGRO\_DISPLAY \*)

  The display which generated the event.

- event.display.orientation

  Contains one of the following values:

  - •

    ALLEGRO\_DISPLAY\_ORIENTATION\_0\_DEGREES

  - •

    ALLEGRO\_DISPLAY\_ORIENTATION\_90\_DEGREES

  - •

    ALLEGRO\_DISPLAY\_ORIENTATION\_180\_DEGREES

  - •

    ALLEGRO\_DISPLAY\_ORIENTATION\_270\_DEGREES

  - •

    ALLEGRO\_DISPLAY\_ORIENTATION\_FACE\_UP

  - •

    ALLEGRO\_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(3alleg5) immediately.

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(3alleg5). 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(3alleg5). 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 call al\_stop\_timer(3alleg5) on all your timers, otherwise they will keep generating events. If you are using audio, you can also stop all audio voices (or pass NULL to al\_set\_default\_voice(3alleg5) 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(3alleg5)

### ALLEGRO\_EVENT\_DISPLAY\_RESUME\_DRAWING

When a display receives this event, it may resume drawing again, and it must call al\_acknowledge\_drawing\_resume(3alleg5) immediately.

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(3alleg5). 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(3alleg5) it is not necessary to reload any bitmaps when you receive this event.

## SINCE

5\.1.0

## SEE ALSO

ALLEGRO\_EVENT\_DISPLAY\_HALT\_DRAWING(3alleg5)

### 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.

- display.source (ALLEGRO\_DISPLAY \*)

  The display which 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 which 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.

- 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 be NULL while the item is being dragged and only set at the final drop.

  *Note*: if the *text* field is not NULL ownership transfers to the event receiver and it must eventually be freed with al\_free.

- drop.is\_file (bool)

  if text is not NULL whether 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 with 0.

- drop.is\_complete (bool)

  indicates that this event will be the last one sent for the drag&drop action. If *is\_complete* is set before receiving an event where *text* was not NULL it 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.
