libtcoddocumentation

2.4.1. Blocking user input

This function stops the application until an event occurs.

Waiting for any event (mouse or keyboard)

This function waits for an event from the user. The eventMask shows what events we're waiting for.
The return value indicate what event was actually triggered. Values in key and mouse structures are updated accordingly.
If flush is false, the function waits only if there are no pending events, else it returns the first event in the buffer.

typedef enum {
        TCOD_EVENT_NONE
=0,
        TCOD_EVENT_KEY_PRESS
=1,
        TCOD_EVENT_KEY_RELEASE
=2,
        TCOD_EVENT_KEY
=TCOD_EVENT_KEY_PRESS|TCOD_EVENT_KEY_RELEASE,
        TCOD_EVENT_MOUSE_MOVE
=4,
        TCOD_EVENT_MOUSE_PRESS
=8,
        TCOD_EVENT_MOUSE_RELEASE
=16,
        TCOD_EVENT_MOUSE
=TCOD_EVENT_MOUSE_MOVE|TCOD_EVENT_MOUSE_PRESS|TCOD_EVENT_MOUSE_RELEASE,
        TCOD_EVENT_ANY
=TCOD_EVENT_KEY|TCOD_EVENT_MOUSE,
    }
TCOD_event_t;
    static
TCOD_event_t TCODSystem::waitForEvent(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse, bool flush)

TCOD_event_t TCOD_sys_wait_for_event(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse, bool flush)

sys_wait_for_event(eventMask,key,mouse,flush)

ParameterDescription
eventMaskevent types to wait for (other types are discarded)
keyupdated in case of a key event. Can be null if eventMask contains no key event type
mouseupdated in case of a mouse event. Can be null if eventMask contains no mouse event type
flushif true, all pending events are flushed from the buffer. Else, return the first available event
Example:

TCOD_key_t key;
TCOD_mouse_t
mouse;
TCOD_event_t
ev = TCODSystem::waitForEvent(TCOD_EVENT_ANY,&key,&mouse,true);
if
( ev == TCOD_EVENT_KEY_PRESS && key.c == 'i' ) { ... open inventory ... }

TCOD_key_t key;
TCOD_mouse_t
mouse;
TCOD_event_t
ev = TCOD_sys_wait_for_event(TCOD_EVENT_ANY,&key,&mouse,true);
if
( ev == TCOD_EVENT_KEY_PRESS && key.c == 'i' ) { ... open inventory ... }