Skip to content

API Class Input

github-actions[bot] edited this page Nov 24, 2026 · 2 revisions

Class: Input

Defined in: src/engine/input/Input.ts:94

Keyboard and pointer input, snapshotted once per frame (ADR 0011 step 2) so getKeyDown gives the same answer everywhere in a frame. Key names are lower-case KeyboardEvent.key values, with "space", "escape" and "enter" as friendly names. What the devices did comes from the device snapshot (devices.ts, ADR 0310), after UI-first routing (ADR 0069).

Constructors

Constructor

new Input(): Input;

Returns

Input

Accessors

anyKeyDown

Get Signature

get static anyKeyDown(): boolean;

Defined in: src/engine/input/Input.ts:111

True if any key or pointer button went down this frame (and didn't go to the UI).

Returns

boolean


inject

Get Signature

get static inject(): DeviceEventSink;

Defined in: src/engine/input/Input.ts:173

Report device events yourself, as an adapter does (ADR 0337): virtual devices (on-screen controls), automation, replaying raw input, tests. Events reach the game at the next frame's snapshot, through UI routing, the device entities and actions, like real devices'. Gamepads are identified by any id ≥ 0 you choose; announce one with gamepadConnected first. Touches and the pen are devices of their own here: unlike the DOM adapter, injecting them doesn't also move or press the pointer.

Input.inject.gamepadConnected({ id: 7, name: "Virtual pad", family: "xbox" });
Input.inject.gamepadButton(7, 0, 1); // buttonSouth down
Returns

DeviceEventSink


keyboardOverUI

Get Signature

get static keyboardOverUI(): boolean;

Defined in: src/engine/input/Input.ts:125

True while a UIInputField is focused: keys go to it, and getKey* report false (ADR 0069).

Returns

boolean


mouseDelta

Get Signature

get static mouseDelta(): Vector2;

Defined in: src/engine/input/Input.ts:151

Pointer movement since the last frame in CSS pixels (+x right, +y down). A drag that starts on the canvas keeps reporting movement outside it. Returns a copy.

Returns

Vector2


mousePosition

Get Signature

get static mousePosition(): Vector2;

Defined in: src/engine/input/Input.ts:143

Pointer position in canvas pixels (origin top-left). Returns a copy.

Returns

Vector2


mouseScrollDelta

Get Signature

get static mouseScrollDelta(): Vector2;

Defined in: src/engine/input/Input.ts:156

Wheel / trackpad scroll since the last frame in pixels (+y = scrolled down). Returns a copy.

Returns

Vector2


pointerOverUI

Get Signature

get static pointerOverUI(): boolean;

Defined in: src/engine/input/Input.ts:120

True when the pointer is over interactable UI (a UIButton or UIInputField, ADR 0069). That frame's mouse-button presses go to the UI: getMouseButtonDown reports false for them, and getMouseButton and getMouseButtonUp stay false for them until they're released.

Returns

boolean

Methods

getKey()

static getKey(key): boolean;

Defined in: src/engine/input/Input.ts:96

True while the key is held (including the frame it went down).

Parameters

key

string

Returns

boolean


getKeyDown()

static getKeyDown(key): boolean;

Defined in: src/engine/input/Input.ts:101

True only in the frame the key went down.

Parameters

key

string

Returns

boolean


getKeyUp()

static getKeyUp(key): boolean;

Defined in: src/engine/input/Input.ts:106

True only in the frame the key was released.

Parameters

key

string

Returns

boolean


getMouseButton()

static getMouseButton(button?): boolean;

Defined in: src/engine/input/Input.ts:130

Mouse button held; the primary touch and the pen's tip are button 0 (the DOM adapter reports them as the pointer).

Parameters

button?

number = 0

Returns

boolean


getMouseButtonDown()

static getMouseButtonDown(button?): boolean;

Defined in: src/engine/input/Input.ts:134

Parameters

button?

number = 0

Returns

boolean


getMouseButtonUp()

static getMouseButtonUp(button?): boolean;

Defined in: src/engine/input/Input.ts:138

Parameters

button?

number = 0

Returns

boolean


requestHidGamepads()

static requestHidGamepads(): Promise<number>;

Defined in: src/engine/input/Input.ts:191

Enhanced gamepads in Chromium browsers (WebHID): open the browser's chooser for DualSense, DualShock 4 and Switch Pro controllers and report the ones the player picks with gyro, accelerometer, adaptive triggers and lights. Call it from a click or key press (the browser requires one). Resolves with how many controllers are now open; 0 where WebHID doesn't exist (other browsers, desktop builds, where SDL already gives all of this) or nothing was picked. Controllers picked once are reopened automatically on later visits.

enhanceButton.addEventListener("click", async () => {
  const opened = await Input.requestHidGamepads();
});

Returns

Promise<number>

Clone this wiki locally