Skip to main content

Module state

Module state 

Source
Expand description

InputState: turns key and controller-button presses and releases plus frame time into a game’s actions, with repeat for held repeatable keys and buttons (game ADR-0015, game ADR-0034), and button chords (ticket 1034). Generic over the game’s ActionSet (ticket 1106).

How a button chord fires. A button chord X+Y fires when one of its buttons goes down while the other is down and still holding back its own actions (Keymap::chord_wait): the chord’s actions instead of either button’s. A button that holds back waits for the chord window (keymap.ron’s chord) or until it is let go, whichever is first, or, if a partner of its acts on press, until it is let go; it then gives its own actions, unless a chord used it while it was held (then nothing). With the Playdate’s A+B, B+← and B+→:

  • A and B pressed within the window, in either order, give End turn and neither Confirm nor Cancel; B held, A any time gives it too.
  • B held, ← gives Previous unit, as often as ← is pressed while B is held, and ← held repeats it as it repeats the cursor; letting go of B then gives nothing.
  • B tapped (or held) alone gives Cancel when it is let go; A alone gives Confirm after the window, or on release if that is sooner.

Buttons in no chord, keys, and every pad whose bindings have no chords act on press exactly as before.

Structs§

InputState
Turns key and controller-button events and elapsed time into actions.

Enums§

Device
What the player is playing with: whatever they pressed last (docs/design/controls.md, Switching between keyboard and controller). Help text names keys or this pad’s buttons to match.
Input
Something the player can hold down: a keyboard key or a controller button (a stick direction counts as a button).

Constants§

MAX_REPEATS_PER_UPDATE
At most this many repeats are emitted by one InputState::update, so a lag spike can’t teleport the cursor across the map.