al_emit_user_event
bool al_emit_user_event(ALLEGRO_EVENT_SOURCE *src,
ALLEGRO_EVENT *event, void (*dtor)(ALLEGRO_USER_EVENT *))
Introduced in 5.0.0
Emit a user event. The event source must have been initialised with al_init_user_event_source. 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 to decrease the reference count once you are done a user event that you have received from al_get_next_event, al_peek_next_event, al_wait_for_event, 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 on non-reference counted user events.
See also: ALLEGRO_USER_EVENT, al_unref_user_event
Examples: ex_native_filechooser, ex_user_events
Most helpful discussions:
- User Events? (2)
- [a5] simulate keystroke? (1)
- ALLEGRO_EVENT_DISPLAY_SWITCH_OUT
- How to handle game state changes?
- A segfault for libmpv
- Synchronizing Threads
- I do not quite understand the custom events mentioned in the user manual
- Redrawing smoothly while display is being resized
- Passing by reference in custom event
- Allegro 5.1.12 released!
Other recent discussions:
- al_emit_user_event() thread safe?
- ASSERT(ALLEGRO_EVENT_TYPE_IS_USER(event->any.type));
- Random deadlocks playing WAV sounds (Windows, MSVC)
- Joystick Event Injection
- [A5] Event and socket messages ?
- Listeners, threads, synchronization
- Crash in d3d_shutdown
- Intro to threading and cpu free waiting for signals
- [A5] User Event are giving me a hard time.
- [A5] simulate_keypress()?