---
name: "al_emit_user_event"
section: "3"
platform: "linux"
package: "allegro"
version: "5.2.11.3-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/al_emit_user_event"
---

# al\_emit\_user\_event(3)

Allegro 5 API

## NAME

al\_emit\_user\_event - Allegro 5 API

## SYNOPSIS

-

  ```
  #include <allegro5/allegro.h>
  bool al_emit_user_event(ALLEGRO_EVENT_SOURCE *src,
     ALLEGRO_EVENT *event, void (*dtor)(ALLEGRO_USER_EVENT *))
  ```

## DESCRIPTION

Emit an event from a user event source. The event source must have been initialised with [al\_init\_user\_event\_source(3)](/al_init_user_event_source/3.md). Returns `false` if the event source isn’t registered with any queues, hence the event wouldn’t have been delivered into any queues.

Events are *copied* in and out of event queues, so after this function returns the memory pointed to by `event` may be freed or reused. Some fields of the event being passed in may be modified by the function.

Reference counting will be performed if `dtor` is not NULL. Whenever a copy of the event is made, the reference count increases. You need to call [al\_unref\_user\_event(3)](/al_unref_user_event/3.md) to decrease the reference count once you are done with a user event that you have received from [al\_get\_next\_event(3)](/al_get_next_event/3.md), [al\_peek\_next\_event(3)](/al_peek_next_event/3.md), [al\_wait\_for\_event(3)](/al_wait_for_event/3.md), etc.

Once the reference count drops to zero `dtor` will be called with a copy of the event as an argument. It should free the resources associated with the event, but *not* the event itself (since it is just a copy).

If `dtor` is NULL then reference counting will not be performed. It is safe, but unnecessary, to call [al\_unref\_user\_event(3)](/al_unref_user_event/3.md) on non-reference counted user events.

You can use al\_emit\_user\_event to emit both user and non-user events from your user event source. Note that emitting input events will not update the corresponding input device states. For example, you may emit an event of type ALLEGRO\_EVENT\_KEY\_DOWN(3), but it will not update the [ALLEGRO\_KEYBOARD\_STATE(3)](/ALLEGRO_KEYBOARD_STATE/3.md) returned by [al\_get\_keyboard\_state(3)](/al_get_keyboard_state/3.md).

## SEE ALSO

[ALLEGRO\_USER\_EVENT(3)](/ALLEGRO_USER_EVENT/3.md), [al\_unref\_user\_event(3)](/al_unref_user_event/3.md)
