Repository navigation
API 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).
new Input(): Input;Input
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).
boolean
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 downget 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).
boolean
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.
get static mousePosition(): Vector2;Defined in: src/engine/input/Input.ts:143
Pointer position in canvas pixels (origin top-left). Returns a copy.
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.
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.
boolean
static getKey(key): boolean;Defined in: src/engine/input/Input.ts:96
True while the key is held (including the frame it went down).
string
boolean
static getKeyDown(key): boolean;Defined in: src/engine/input/Input.ts:101
True only in the frame the key went down.
string
boolean
static getKeyUp(key): boolean;Defined in: src/engine/input/Input.ts:106
True only in the frame the key was released.
string
boolean
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).
number = 0
boolean
static getMouseButtonDown(button?): boolean;Defined in: src/engine/input/Input.ts:134
number = 0
boolean
static getMouseButtonUp(button?): boolean;Defined in: src/engine/input/Input.ts:138
number = 0
boolean
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();
});Promise<number>
This wiki is generated from docs/wiki/ and the myco module's source on every push to master. Change pages there in a pull request: edits made here are not kept.
Basics
Gameplay
Rendering
Audio
- Playing sound
- Why is there no sound?
- Playlists
- Interactive music
- Sound generators
- Spatial audio
- Audio mixer
- Live mixing
- Loudness
- Audio profiler
- Audio takes
Reference