input API

← input · version 0.2.6

18 public items, in source order. Generated from the registry index, which re-derives them from the package source at publish time — so a signature here is the one that version actually ships.

pub struct ActionBinding { const ab_name: text, const ab_keys: vector<integer> }

One named action: "jump" → [KEY_SPACE, KEY_UP] (any of the listed keys triggers the action). An empty ab_keys is degenerate but valid — the action will simply never fire.

pub struct AxisBinding { const ax_name: text, const ax_neg: integer, const ax_pos: integer }

One named axis: pair of (negative key, positive key) → -1.0 / 0.0 / +1.0. If both are down simultaneously the axis reads 0.0 (they cancel) — same convention as Unity / Godot's built-in axis pairs.

pub struct Bindings { const bnd_actions: vector<ActionBinding>, const bnd_axes: vector<AxisBinding> }

Full binding set — game code constructs this once and passes it into input_new. Re-binding at runtime: mutate this struct in place (or build a new one) and call input_set_bindings.

pub struct InputState { is_bindings: Bindings, const is_keys_now: vector<boolean>, const is_keys_prev: vector<boolean>, is_mouse_x: float, is_mouse_y: float, is_mouse_buttons_now: integer, is_mouse_buttons_prev: integer, is_mouse_wheel: integer }

Abstract input state. Fields are documented but considered opaque — query via the is_action_* / get_axis / mouse_* functions below.

is_keys_now[i] is true if key code i is currently down; is_keys_prev[i] holds the same flag from the previous tick so edge detection compares the two. Mouse buttons are a bitmask (MB_LEFT | MB_RIGHT | …).

pub fn input_new(b: Bindings) -> InputState

Construct an InputState from a Bindings set. Both key tables start fully released; the first call to input_tick populates is_keys_now (and is_keys_prev stays all-false, so any key down on the first tick fires its just_pressed edge — the documented "first frame counts as a transition" semantics).

pub fn input_set_bindings(self: &InputState, b: Bindings)

Replace the binding set on a live state (e.g. after the player remaps keys in a settings menu). Does NOT clear the key tables — in-flight key presses survive the rebind so a remap doesn't strand an already-held key.

pub fn input_tick(self: &InputState)

Poll the graphics input primitives and refresh state for one tick. Reads gl_key_pressed for every key code referenced by the current bindings (avoids a 256-call sweep — only ask about keys the game actually cares about), plus gl_mouse_x/gl_mouse_y/ gl_mouse_button/gl_mouse_wheel unconditionally.

pub fn input_tick_from_state( self: &InputState, keys: const vector<boolean>, mx: float, my: float, mbtn: integer, wheel: integer )

Advance state from a caller-supplied snapshot instead of polling graphics. Used by tests (no GL context) and by network replay / record-playback systems. keys length is clamped to KEY_MAX; out-of-range entries are ignored.

pub fn is_action_pressed(self: const InputState, action: text) -> boolean

True if ANY of the action's bound keys is currently down.

pub fn is_action_just_pressed(self: const InputState, action: text) -> boolean

True for exactly one tick: the moment any of the action's bound keys transitions from up to down. If multiple bound keys all transition on the same tick it still fires once.

pub fn is_action_just_released(self: const InputState, action: text) -> boolean

True for exactly one tick: the moment any of the action's bound keys transitions from down to up.

pub fn get_axis(self: const InputState, axis: text) -> float

Read an axis pair: -1.0 if only ax_neg is down, +1.0 if only ax_pos is down, 0.0 if neither or both. Unknown axis name returns 0.0.

pub fn mouse_x(self: const InputState) -> float

Mouse position — pixels from the top-left of the window (matches graphics::gl_mouse_x / gl_mouse_y).

pub fn mouse_y(self: const InputState) -> float

The pointer's y this frame, the companion of mouse_x.

pub fn mouse_button_down(self: const InputState, button: integer) -> boolean

True if the given mouse button (MB_LEFT / MB_RIGHT / MB_MIDDLE) is currently down. Pass the constant, not a bitmask of multiple.

pub fn mouse_button_just_pressed(self: const InputState, button: integer) -> boolean

True for exactly one tick — the moment the button transitions from up to down.

pub fn mouse_button_just_released(self: const InputState, button: integer) -> boolean

True for exactly one tick — the moment the button transitions from down to up.

pub fn mouse_wheel(self: const InputState) -> integer

Accumulated scroll-wheel delta since the last input_tick — positive = scroll up. Mirrors graphics::gl_mouse_wheel.