Skip to content

Polling of input states

Finalspace edited this page May 29, 2026 · 2 revisions

Table of Contents

Overview

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

Disable Input-Events

If you 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.

 keyboardState;
if ((&keyboardState)) {
    if (keyboardState.[] >= ) {
        // 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.

 gamepadStates;
if ((&gamepadStates)) {
    for (int index = 0; index < (gamepadStates.); ++index) {
         *gamepadState = gamepadStates. + 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.

 mouseState;
if ((&mouseState)) {
    int mousePosX = mouseState.;
    int mousePosY = mouseState.;
    if (mouseState.[] >= 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!

Polling without a window

When the application runs without a window (FPL_NO_WINDOW or fplInputSettings::detachFromWindow), the input subsystem is not driven by a window event loop. Call fplUpdateInputDevices once per frame to refresh cached state and dispatch gamepad connect/disconnect events. fplPollEvent and fplPollEvents also work in this mode and drive the input subsystem internally.

See Using input without a window for a full example.

Final Platform Layer

Pages

Topics

Data Structures

Clone this wiki locally