libtcoddocumentation

2.4.2. Non blocking user input

The prefered way to check for user input is to use checkForEvent below, but you can also get the status of any special key at any time with :

static bool TCODConsole::isKeyPressed(TCOD_keycode_t key)

bool TCOD_console_is_key_pressed(TCOD_keycode_t key)

console_is_key_pressed(key)

ParameterDescription
keyAny key code defined in keycode_t except TCODK_CHAR (Char) and TCODK_NONE (NoKey)

Checking for any event (mouse or keyboard)

This function checks if an event from the user is in the buffer. The eventMask shows what events we're waiting for.
The return value indicate what event was actually found. Values in key and mouse structures are updated accordingly.

typedef enum {
        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::checkForEvent(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse)

TCOD_event_t TCOD_sys_check_for_event(int eventMask, TCOD_key_t *key, TCOD_mouse_t *mouse)

sys_check_for_event(eventMask,key,mouse)

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
Example:

TCOD_key_t key;
TCOD_mouse_t
mouse;
TCOD_event_t
ev = TCODSystem::checkForEvent(TCOD_EVENT_ANY,&key,&mouse);
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_check_for_event(TCOD_EVENT_ANY,&key,&mouse);
if
( ev == TCOD_EVENT_KEY_PRESS && key.c == 'i' ) { ... open inventory ... }