Skip to content

InputActionRouter

Extends EngineObject.

Turns the player's input into the actions of an InputActionMap that fire in the active contexts, and says how far analog actions are pushed. Of the bindings on an input whose modifiers are all held, the one with the most modifiers wins, so Shift+Tab isn't also Tab, and a key still fires while running with Shift. A key with a hold binding fires its press on a quick release instead; a key with a double tap waits a moment for the second tap before firing its press. InputDevices feeds it from SDL; Press, Release, Axis and Poll feed it by hand, with explicit times (seconds, any origin), for tests and replays. Call Update once a frame to raise ActionFired, and EndFrame after the frame's logic ran.

Create one with InputActionRouter.new().

Properties

  • map: InputActionMap? The actions to route. The router takes the map over: it lives as long as the router does.
  • contexts: { string } The active contexts (a situation); none ignores every input. A game sets them every frame from what the player is doing.
  • is_gamepad_last: boolean True when the last input pressed was on a gamepad (the labels then name its buttons). Read-only.

Signals

  • action_fired: Signal<string>
  • captured: Signal<string> The binding text of what was pressed while Listen was on.

Methods

in_context

function in_context(self, action: string): boolean

listen

function listen(self): ()

Rebinding: the next key (with the modifiers held), mouse button, wheel step, gamepad button or stick or trigger pushed past half way is not routed; Captured gets its binding text (Shift+F, Joy LY-) at the next Update, and listening ends. A modifier key alone does not count: it waits for the key it goes with.

stop_listening

function stop_listening(self): ()

press

function press(self, input: string, modifiers: { Modifiers }, time: number): ()

An input goes down. modifiers are the Ctrl, Shift and Alt held with it, not counting the input itself.

release

function release(self, input: string, time: number): ()

An input goes up.

axis

function axis(self, axis: string, value: number, time: number): ()

An axis moves: Joy LX, Joy LY, Joy RX, Joy RY (-1..1), Joy LT, Joy RT (0..1), or the mouse's motion in pixels since the last event (Mouse X, Mouse Y), which adds up until EndFrame.

end_frame

function end_frame(self): ()

The frame's logic has read the mouse's motion: it starts again from zero.

release_all

function release_all(self): ()

Everything let go and forgotten: the window lost focus, or the game is changing screens.

poll

function poll(self, time: number): { string }

Fires what time has made due (a hold that has been held long enough, a tap that no second tap followed) and returns the actions fired since the last call, in order. An action bound to several inputs fires once for each.

update

function update(self, time: number): ()

Poll, and raises ActionFired for each action and Captured for a binding that was listened for. Once a frame, before the logic that reads the actions.

get_down

function get_down(self): { string }

The inputs that are down, sorted.

get_strength

function get_strength(self, action: string): number

How far an action is pushed: 0 to 1 for keys, buttons, sticks and triggers (the largest of its bindings), more for the mouse's motion; 0 outside its contexts.

is_held

function is_held(self, action: string): boolean

get_label

function get_label(self, action: string): string

What to press for an action, as the player's keyboard names it (Z on AZERTY for a W binding), or its gamepad button when the gamepad was used last; an en dash when it is unbound.

Functions

label_binding

InputActionRouter.label_binding: (text: string) -> string

A binding as the player reads it: Hold Ctrl+Left mouse, Pad A, and a key by what it types on their keyboard layout.