2.4.2. Non blocking keyboard input
This function checks if the user has pressed a key. It returns the code of the key pressed as well as the corresponding character. See TCOD_key_t. If the user didn't press a key, this function returns the key code TCODK_NONE (NoKey for C# and Lua).
Note that key repeat only results in TCOD_KEY_PRESSED events.
static TCOD_key_t TCODConsole::checkForKeypress(int flags=TCOD_KEY_RELEASED)
TCOD_key_t key = TCOD_console_check_for_keypress(TCOD_KEY_PRESSED);
if ( key.vk == TCODK_NONE ) return; // no key pressed
if ( key.c == 'i' ) { ... open inventory ... }
key = libtcod.console_check_for_keypress()
if key.vk == libtcod.KEY_NONE return # no key pressed
if key.c == ord('i') :
static TCODKey TCODConsole::checkForKeypress(int flags)
tcod.console.checkForKeypress(flags)
Parameter | Description |
---|---|
flags | A filter for key events (C# and Lua in parenthesis): TCOD_KEY_PRESSED (KeyPressed) : only keypress events are returned TCOD_KEY_RELEASED (KeyReleased): only key release events are returnes TCOD_KEY_PRESSED|TCOD_KEY_RELEASED (KeyPressed+KeyReleased): events of both types are returned. |
Example:
TCOD_key_t key = TCODConsole::checkForKeypress();
if ( key.vk == TCODK_NONE ) return; // no key pressed
if ( key.c == 'i' ) { ... open inventory ... }
key = tcod.console.checkForKeypress()
if key.KeyCode == tcod.NoKey then return end -- no key pressed
if key.Character == 'i' then ... open inventory ... end
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)
static bool TCODConsole::isKeyPressed(TCODKeyCode key)
tcod.console.isKeyPressed(key)
Parameter | Description |
---|---|
key | Any key code defined in keycode_t except TCODK_CHAR (Char) and TCODK_NONE (NoKey) |