Final Platform Layer  0.9.6-beta
Polling of input states

Overview

FPL supports manual polling of input states for Keyboard/Gamepad/Mouse as well.

Disable Input-Events

If you are only use polling to get your input states, you should disable the input-events entirely.
This is done by simply setting the fplInputSettings::disabledEvents to "1" in your fplSettings structure.

Keyboard

Use fplPollKeyboardState to poll the current keyboard state.
This state contains all the raw/mapped button states and the modifier states.

fplKeyboardState keyboardState;
if (fplPollKeyboardState(&keyboardState)) {
if (keyboardState.buttonStatesMapped[fplKey_Space] >= fplButtonState_Press) {
// Spacebar pressed
}
}

See fplKeyboardState for more details.

Gamepad

Use fplPollGamepadStates to poll the current states for all connected game controllers.
This state contains all the buttons, digital-pad, the left/right stick position + trigger, etc.

fplGamepadStates gamepadStates;
if (fplPollGamepadStates(&gamepadStates)) {
for (int index = 0; index < fplArrayCount(gamepadStates.deviceStates); ++index) {
fplGamepadState *gamepadState = gamepadStates.deviceStates + index;
// ... do something with the gamepad state
}
}

See fplGamepadStates for more details.

Note
use fplGamepadState::isConnected to check if the gamepad is connected or not.

Mouse

Use fplPollMouseState to poll the current mouse state.
This state contains the state of all the buttons (Left, Right, Middle) and the position in pixels coordinates.

fplMouseState mouseState;
if (fplPollMouseState(&mouseState)) {
int mousePosX = mouseState.x;
int mousePosY = mouseState.y;
if (mouseState.buttonStates[fplMouseButtonType_Left] >= fplButtonState_Pressed) {
// Left mouse button down
}
}

See fplMouseState for more details.

Tips

Note
You can always use all those polling functions, regardless of the fplInputSettings::disabledEvents field!
fplGamepadState
A structure containing the entire gamepad state.
Definition: final_platform_layer.h:5964
fplGamepadStates
A struct containing the full state for all gamepad devices.
Definition: final_platform_layer.h:6111
fplMouseState::x
int32_t x
X-Position in pixels.
Definition: final_platform_layer.h:6121
fplMouseButtonType_Left
Left mouse button.
Definition: final_platform_layer.h:5884
fplPollKeyboardState
fpl_platform_api bool fplPollKeyboardState(fplKeyboardState *outState)
Polls the current keyboard state and writes it out into the output structure.
fplMouseState::buttonStates
fplButtonState buttonStates[fplMouseButtonType_MaxCount]
Mouse button states mapped to fplMouseButtonType.
Definition: final_platform_layer.h:6119
fplMouseState
A struct containing the full mouse state.
Definition: final_platform_layer.h:6117
fplArrayCount
#define fplArrayCount(arr)
Returns the element count from a static array. This should ideally produce a compile error when passi...
Definition: final_platform_layer.h:2254
fplGamepadStates::deviceStates
fplGamepadState deviceStates[FPL_MAX_GAMEPAD_STATE_COUNT]
Device states.
Definition: final_platform_layer.h:6113
fplKeyboardState::buttonStatesMapped
fplButtonState buttonStatesMapped[FPL_MAX_KEYBOARD_STATE_COUNT]
Mapped button states.
Definition: final_platform_layer.h:6104
fplButtonState_Press
Key pressed.
Definition: final_platform_layer.h:5808
fplPollMouseState
fpl_platform_api bool fplPollMouseState(fplMouseState *outState)
Polls the current mouse state and writes it out into the output structure.
fplKeyboardState
A struct containing the full keyboard state.
Definition: final_platform_layer.h:6098
fplPollGamepadStates
fpl_platform_api bool fplPollGamepadStates(fplGamepadStates *outStates)
Polls the current gamepad states and writes it out into the output structure.
fplMouseState::y
int32_t y
Y-Position in pixels.
Definition: final_platform_layer.h:6123