Cross-platform C SDK logo

Cross-platform C SDK

Keyboard buffer

❮ Back
Next ❯
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)
voidkeybuf_destroy (...)
voidkeybuf_OnUp (...)
voidkeybuf_OnDown (...)
voidkeybuf_clear (...)
bool_tkeybuf_pressed (...)
voidkeybuf_str (...)
voidkeybuf_dump (...)

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.

Image representing the keyboard buffer to connect asynchronous keystroke events with synchronous read events.
Figure 1: Access to key status in synchronous events.
❮ Back
Next ❯

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 NULL after the destruction.


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.

❮ Back
Next ❯