-
Notifications
You must be signed in to change notification settings - Fork 0
csInput
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.
A constant variable with the value of 21; the size of 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].
cInputState cGetInputState(bool useMouse)
See cInputState.
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.
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.
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.
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.