Skip to content
Cursor Agent edited this page Nov 29, 2026 · 1 revision

Input

Game code does not subscribe to a blocking event bus. winit delivers press and release events to fanalor-core. Input turns those into a snapshot for the current frame: which keys and buttons are held, which were pressed or released this frame, the cursor, the mouse delta, and scroll.

Call Input::end_frame once per frame after the frame is handled. Nothing else clears the per-frame sets. An edge such as "jump was pressed" is visible once, in update. fixed_update can run more than once in a frame, so it is the wrong place to read an edge.

The winit event types stay inside fanalor-core. Tests and gameplay call backend-agnostic methods (on_key and the action queries), because a winit key event cannot be built outside that crate.

Actions

Named actions sit on top of the snapshot. assets/default.input.ron is the map a game ships; fanalor-core loads default.input.ron from the asset root with no extra code. An action names the controls that drive it: keys, mouse buttons, gamepad buttons and axes, and touch zones.

let direction = Vec2::new(
    tick.input.action_axis("move_left", "move_right"),
    tick.input.action_axis("move_down", "move_up"),
);
let jump = tick.input.action("jump").pressed();

action_axis is the difference of two actions, in -1.0..=1.0. Analog sticks pass through a dead zone. tick.actions is the map itself, which is what rebinding writes.

Rebound controls are saved with the game's other saves, on every platform including the web. The options screen from cargo xtask new-game exposes that rebinding. See Building Games.

Raw key reads stay available. An editor shortcut is a key, not an action: the editor's W / E / R tools are keys, and they are not stolen by the game's action map while you are editing.

Pads, touch, and text

Every connected gamepad is merged into one player. While the window is unfocused, pad input is ignored so a backgrounded game is not steered. Focus returning does not synthesize a fresh edge for a button that was already down.

Touch treats fingers as pointers. A tap is a click. Virtual sticks and buttons are touch zones in the action map, so the same action_axis calls work on a touchscreen.

A focused text field reads Input's typing state: characters, editing keys, and IME composition. The caret follows visual order for bidirectional text.

The frame, not a callback

App (and a game's update / fixed_update) runs from the redraw, after the window events for that frame have been folded into Input. There is no per-event callback for gameplay, and no layer stack that eats events on the way down. Window resize and close are handled by the event loop in fanalor-core before the game tick.

UI focus is one chain for mouse, keys, pads, and touch. tick.ui says what was clicked. Dropdowns, sliders, text fields, and the rest are in the UI chapter.

On the web, the canvas takes the keyboard from the start. Sound stays silent until the first key, click, or touch, because the browser requires a user gesture. That is a platform rule, not a different input API: the game still reads actions.

Clone this wiki locally