Skip to content

Documentation / @debuffjp/input / Input

Class: Input<A> ​

Defined in: input.ts:54

Action-based input across keyboard, pointer and gamepad.

ts
const input = new Input(game, {
  bindings: { left: ["ArrowLeft", "KeyA", "PadLeft"], jump: ["Space", "PadA", "Pointer"] },
});
if (input.pressed("jump")) jump();
const dx = input.axis("left", "right");

Edges are cleared automatically after each simulation step.

Type Parameters ​

A ​

A extends string

Constructors ​

Constructor ​

new Input<A>(host, options): Input<A>

Defined in: input.ts:73

Parameters ​

host ​

InputHost

options ​

InputOptions<A>

Returns ​

Input<A>

Properties ​

bindings ​

readonly bindings: Bindings<A>

Defined in: input.ts:62

The current bindings: Input's own copy of the options' map, read on every call. Change them with rebind(), which keeps keys.captured in step.


keys ​

readonly keys: Keyboard

Defined in: input.ts:55


pads ​

readonly pads: Gamepads

Defined in: input.ts:57


pointer ​

readonly pointer: Pointer

Defined in: input.ts:56


virtual ​

readonly virtual: Map<string, ButtonState>

Defined in: input.ts:67

Sources other code sets each step, by binding name: TouchControls writes "TouchStickLeft", "TouchA" and so on here. A binding found in this map reads from it instead of the keyboard.

Methods ​

axis() ​

axis(negative, positive): number

Defined in: input.ts:146

-1, 0 or 1 from two opposing actions, e.g. axis("left", "right").

Parameters ​

negative ​

A

positive ​

A

Returns ​

number


dispose() ​

dispose(): void

Defined in: input.ts:150

Returns ​

void


down() ​

down(action): boolean

Defined in: input.ts:95

Any binding for the action is held.

Parameters ​

action ​

A

Returns ​

boolean


pressed() ​

pressed(action): boolean

Defined in: input.ts:108

The action started this step.

Parameters ​

action ​

A

Returns ​

boolean


rebind() ​

rebind(action, keys): void

Defined in: input.ts:138

Replace an action's bindings, e.g. from a controls menu: input.rebind("jump", ["KeyK", "PadA"]). Takes a copy of keys, and updates keys.captured so the new keys stop scrolling the page and the old ones scroll it again.

Parameters ​

action ​

A

keys ​

readonly string[]

Returns ​

void


released() ​

released(action): boolean

Defined in: input.ts:121

The action ended this step.

Parameters ​

action ​

A

Returns ​

boolean