Skip to content

1681-engine / index / Bindings

Type Alias: Bindings<A> ​

ts
type Bindings<A> = Record<A, readonly string[]>;

Defined in: src/input/Actions.ts:31

Named actions bound to any input: keys, gamepad buttons and sticks, and virtual buttons a touch UI presses. Game code asks for 'jump', never for Space, so players can rebind and every device works the same.

ts
const input = new Actions(keyboard, {
  left: ['KeyA', 'ArrowLeft', 'pad:left', 'pad:lx-'],
  right: ['KeyD', 'ArrowRight', 'pad:right', 'pad:lx+'],
  jump: ['Space', 'pad:a'],
});
// in a fixed system:
input.poll();
if (input.pressed('jump')) …
const [x, y] = input.vector('left', 'right', 'up', 'down');
input.endStep();

Bindings: a KeyboardEvent.code (KeyW, Space, ArrowUp), a chord of modifiers and a code (Shift+Tab, Ctrl+KeyS: Shift, Ctrl, Alt, Meta, either side), pad:<button> (standard mapping names below), pad:<axis>+ / pad:<axis>- for a stick half (lx, ly, rx, ry), or touch:<name> for a virtual button (press/release).

A chord wins over its bare key: while Shift+Tab is held, an action bound to plain Tab is not, and it stays off until Tab itself comes up (letting Shift go first must not turn a Shift+Tab into a Tab). A bare key held with a modifier no chord names still counts (Shift held to run does not stop the jump key).

Type Parameters ​

Type Parameter
A extends string

Released under the MIT License.