Keyboard buffer
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.
Buffer to read keystrokes synchronously.
Functions
KeyBuf* | keybuf_create (void) |
void | keybuf_destroy (...) |
void | keybuf_OnUp (...) |
void | keybuf_OnDown (...) |
void | keybuf_clear (...) |
bool_t | keybuf_pressed (...) |
void | keybuf_str (...) |
void | keybuf_dump (...) |
- Use keybuf_create to create the buffer.
- Use view_keybuf to bind the buffer to any graphical view.
The operating system generates events asynchronously every time the user presses or releases a key. We can capture such events using a callback function (see view_OnDown), but sometimes this is not enough. Let's think about a video game where we must read the state of a key in the update phase, which occurs synchronously. In these cases, the use of a keyboard buffer (Figure 1) will be very useful, which simply saves the state of each key based on the events that occur. This status can be read at any time during execution.
keybuf_create ()
Create a buffer with keyboard status.
KeyBuf* keybuf_create(void);
Return
The buffer.
keybuf_destroy ()
Destroy the buffer.
void keybuf_destroy(KeyBuf **bufer);
bufer | The buffer. It will be set to |
keybuf_OnUp ()
Set the state of a key as released.
void keybuf_OnUp(KeyBuf *bufer, const vkey_t key);
bufer | The buffer. |
key | The key code. |
Remarks
Normally it will not be necessary to call this function. It will be done by View or the module that captures keyboard events.
keybuf_OnDown ()
Sets the state of a key as pressed.
void keybuf_OnDown(KeyBuf *bufer, const vkey_t key);
bufer | The buffer. |
key | The key code. |
Remarks
Normally it will not be necessary to call this function. It will be done by View or the module that captures keyboard events.
keybuf_clear ()
Clear the buffer. Set all keys as released.
void keybuf_clear(KeyBuf *bufer);
bufer | The buffer. |
Remarks
Normally it will not be necessary to call this function. It will be done by View or the module that captures keyboard events.
keybuf_pressed ()
Returns the state of a key.
bool_t keybuf_pressed(const KeyBuf *bufer, const vkey_t key);
bufer | The buffer. |
key | The key code. |
Return
Pulsed (TRUE
) or released (FALSE
).
keybuf_str ()
Returns a text string associated with a key.
void keybuf_str(const vkey_t key);
key | The key code. |
keybuf_dump ()
Dump the buffer status into the Log.
void keybuf_dump(const KeyBuf *bufer);
bufer | The buffer. |