KallistiOS git master
Independent SDK for the Sega Dreamcast
|
Frame-based polling for keyboard input More...
Functions | |
kbd_state_t * | kbd_get_state (maple_device_t *device) |
Retrieves the keyboard state from a maple device. | |
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);
Then let's "move" every frame an arrow key is held down:
if(kbd->matrix[KBD_KEY_LEFT] == KEY_STATE_PRESSED) printf("Moving left!\n"); if(kbd->matrix[KBD_KEY_RIGHT] == KEY_STATE_PRESSED) printf("Moving right!\n"); if(kbd->matrix[KBD_KEY_UP] == KEY_STATE_PRESSED) printf("Moving up!\n"); if(kbd->matrix[KBD_KEY_DOWN] == KEY_STATE_PRESSED) printf("Moving down!\n");
Finally, let's charge an "attack" incrementing the charge for each frame that the key is held and resetting when the key is released:
if(kbd->matrix[KBD_KEY_SPACE] == KEY_STATE_PRESSED) charge++; if(kbd->matrix[KBD_KEY_SPACE] == KEY_STATE_WAS_PRESSED) { printf("Releasing a charged attack of %i!\n", charge); charge = 0; }
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.
device | Handle corresponding to a MAPLE_FUNC_KEYBOARD device. |
kbd_state_t* | A pointer to the internal keyboard state on success. |
NULL | On failure. |