Skip to content

csInput

Stephen P edited this page Oct 14, 2021 · 3 revisions

CoSprite's input handling lives here. Helper functions and structs help you gather key inputs, set customizable keys, and get text input easily. Also, like most CoSprite header files, defines the bool type, boolToString(), and NULL.

Structs

Global Variables

MAX_KEYMAPS

A constant variable with the value of 21; the size of keymaps.

keymaps

SDL_Scancode keymaps[MAX_KEYMAPS]
Easy customizable keymaps. Several defines make common keys easy to program with. KEY_UP -> keymaps[0], KEY_DOWN -> keymaps[1], KEY_LEFT -> keymaps[2], KEY_RIGHT -> keymaps[3], KEY_CONFIRM -> keymaps[4], KEY_BACK -> keymaps[5]. As well, KEY_CUSTOM(x) with x = {1 through 15} gives keymaps[x+5].

Methods

cGetInputState

cInputState cGetInputState(bool useMouse)
See cInputState.

getKey

SDL_Keycode getKey(bool useMouse)
If a key is pressed around the time this is run (within a "frame"), sends the keycode pressed. If not, sends SDLK_UNKNOWN. If useMouse is true, a mouse click counts as an input, and returns 1.

waitForKey

SDL_Keycode waitForKey(bool useMouse)
Waits for a key to be pressed. If useMouse is true, a mouse click counts as an input, and returns 1.

setKey

bool setKey(SDL_Scancode key, int keyslot)
Sets a certain keyslot to the key given. See keymaps for the keyslot indexes for Up, Down, Left, Right, Confirm, and Back, as well as the formula for the custom indexes.

handleTextInput

void handleTextInput(char* text, SDL_Keycode key, int maxChar)
An easy function to help handle text input. You must allocate the string passed to text, and provide its max length in maxChar. In a loop, collect an SDL_Keycode, pass it in through this function through key, and this function will build the text that's typed in by the user.

Clone this wiki locally