KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches

Frame-based polling for keyboard input More...

Functions

kbd_state_tkbd_get_state (maple_device_t *device)
 Retrieves the keyboard state from a maple device.
 

Detailed Description

Frame-based polling for keyboard input

One method of checking for key input is to simply poll kbd_state_t::matrix for the desired key states each frame.

First, lets grab a pointer to the kbd_state_t:

kbd_state_t *kbd = kbd_get_state(device);
kbd_state_t * kbd_get_state(maple_device_t *device)
Retrieves the keyboard state from a maple device.
Keyboard status structure.
Definition keyboard.h:369

Then let's "move" every frame an arrow key is held down:

printf("Moving left!\n");
printf("Moving right!\n");
printf("Moving up!\n");
printf("Moving down!\n");
#define KEY_STATE_PRESSED
Definition keyboard.h:330
KBD_KEY_LEFT
Left Arrow key.
Definition keyboard.h:276
KBD_KEY_RIGHT
Right Arrow key.
Definition keyboard.h:275
KBD_KEY_UP
Up Arrow key.
Definition keyboard.h:278
KBD_KEY_DOWN
Down Arrow key.
Definition keyboard.h:277
uint8_t matrix[KBD_MAX_KEYS]
Key array.
Definition keyboard.h:381

Finally, let's charge an "attack" incrementing the charge for each frame that the key is held and resetting when the key is released:

charge++;
printf("Releasing a charged attack of %i!\n", charge);
charge = 0;
}
#define KEY_STATE_WAS_PRESSED
Definition keyboard.h:329
KBD_KEY_SPACE
Space key.
Definition keyboard.h:241

Function Documentation

◆ kbd_get_state()

kbd_state_t * kbd_get_state ( maple_device_t * device)

Retrieves the keyboard state from a maple device.

Accessor method for safely retrieving a kbd_state_t from a maple_device_t of a MAPLE_FUNC_KEYBOARD type. This function also checks for whether the given device is actually a keyboard and for whether it is currently valid.

Parameters
deviceHandle corresponding to a MAPLE_FUNC_KEYBOARD device.
Return values
kbd_state_t*A pointer to the internal keyboard state on success.
NULLOn failure.