Skip to main content

Module keymap

Module keymap 

Source
Expand description

The keymap file format, generic over a game’s ActionSet (game ADR-0015, game ADR-0031, game ADR-0034, tickets 1106 and 1107): Keys and Chords, controller Buttons and ButtonChords (two buttons together), the named Layouts a file lists, and KeymapDef, a validated keymap file: each layout’s default keys, the keys that work before a layout is chosen, the default buttons, key-repeat timings and the sticks’ thresholds.

Nothing here names one game’s actions or layouts: a game gives its actions as an ActionSet (action_set) and its file’s text. As a format (ADR-0007): KeymapRon.

Re-exports§

pub use action_set::ActionSet;
pub use action_set::UiAction;

Modules§

action_set
What a game’s input actions are to the input mechanism (ticket 1106): ActionSet, implemented by the game’s own action enum, and UiAction, the few actions the generic widgets and screens react to. UiAction is an action set too, ready-made for a game that plays with the six moves alone (ADR-0036).

Structs§

ButtonChord
What a controller binding is: one Button, or two pressed together (a button chord, ticket 1034), written "South+East" in keymap files and saved bindings. The two are kept in Button::ALL order, so "East+South" is the same chord as "South+East" (and is shown as the latter). How a chord fires is the input’s business (shuyi_ui::input::state).
Chord
A key plus modifier state, e.g. h or Shift+h. Shift+h and h are different chords.
ChordDef
How ButtonChords fire (shuyi_ui::input::state): a chord button whose own action waits for its partner waits at most window_ms (unless it waits for its release).
CrankDef
How a crank turns into Button::CrankBack and Button::CrankForward presses (shuyi_ui::input::crank): one per notch_degrees wound.
KeymapDef
The validated keymap: every Layout’s default keys, the layout picker’s bindings, the default controller buttons, plus the key-repeat timings and stick thresholds they share.
KeymapRon
The keymap file (keymap, .ron) of a game whose actions are A, checked as KeymapDef::from_source says.
Layout
A complete set of key bindings the player can pick: one entry of layouts in the keymap file, named by its id. The file decides which layouts there are; this is only the name, kept inline so a layout is Copy. Names are ASCII letters, digits and _, at most LAYOUT_NAME_MAX bytes (RightHanded).
RepeatDef
Key-repeat timings for held repeatable actions.
StickDef
How far a stick must be pushed to count as a held direction (Button::LeftStickUp and the rest), in percent of its full travel. release_percent is below press_percent, so a stick resting near the edge of the dead zone doesn’t flicker.

Enums§

Button
A controller button, named by its position on an Xbox-shaped pad, whatever is printed on it (game ADR-0034). Each stick’s four directions count as buttons too, and so does a crank wound one notch either way (the Playdate’s, ticket 1035: pressed and let go once per notch), and so does an item of the game’s own in the system’s menu (pressed and let go when the player picks it, ADR-0008 §3). app translates what the platform reports to these; anything else on a pad is ignored, and so are the system’s own buttons (the Playdate’s Menu and Lock, the Deck’s Steam and Quick Access), which no keymap can name.
Key
A hardware-agnostic keyboard key. app translates platform key codes to these; anything without a variant is ignored.

Constants§

LAYOUT_NAME_MAX
Most bytes in a Layout’s name.
SLOTS
Key slots per action: a layout lists at most this many chords for an action, and the player can give each action up to this many keys (docs/design/controls.md, Rebinding keys).
SYSTEM_MENU_ITEMS
The system menu items a keymap can name: Button::SystemMenu0 to Button::SystemMenu7. A target holds fewer (shuyi_assets::target::Input::system_menu_slots).

Type Aliases§

Bindings
Validated bindings as a lookup: each chord maps to exactly one action (of one group). Unbound chords are absent.
LayoutKeys
One layout’s default keys: every action with its chords in the order the keymap file lists them (at most SLOTS, none reserved), no chord on two actions of one group. The order matters: the first chord is the one help text names, and the chords fill the player’s key slots in this order.
LayoutNames
The layouts in file order, each with the text key of its name.
PadKeys
The default controller buttons: every action with its buttons and button chords in the order the keymap file lists them (at most SLOTS), none on two actions of one group. One table for every layout.