Skip to content

cInputState

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

A struct to hold a complex input state. Can hold every key pressed on the keyboard pressed, a click event, and flags to decide if there is a click input or not, and if the input is a quit-like input.

Members

keyStates

const Uint8*
An array of unsigned 8-bit integers that hold the state of all keys on the keyboard. Interface with this using SDL_SCANCODE defines; to get a boolean value determining if a key is pressed or not, use the following: keyStates[SDL_SCANCODE_<key>]. Gives 1 if pressed, 0 if unpressed.

click

SDL_MouseButtonEvent
Holds the latest SDL mouse click event. See the SDL Documentation for more information.

motion

SDL_MouseMotionEvent
Holds the latest SDL mouse motion event. See the SDL Documentation for more information.

keysym

SDL_Keysym
Holds the latest SDL keyboard information, in a different manner than the raw inputs from keyStates. See the SDL Documentation for more information.

isClick

bool
A flag to signal if there was a click input collected. If true, click is filled with a valid click input. If false, click should be ignored and not read to determine inputs.

quitInput

bool
A flag to signal if the input given was quit-like; In particular, if an SDL_QUIT event type is triggered (the window close button is clicked, the task is ended somehow, etc). For each time you read a cInputState, it is best practice to only continue the current loop/game state if the user isn't trying to quit.

Functions

cGetInputState

cInputState cGetInputState(bool useMouse)
Gets the current input state this frame/input window and returns a cInputState. If useMouse is true, mouse click events will be collected.

Clone this wiki locally