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:176
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:128
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:154
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:146
Pointer position in canvas pixels (origin top-left). Returns a copy.
get static mouseScrollDelta(): Vector2;Defined in: src/engine/input/Input.ts:159
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:123
True when the pointer is over UI that stops it: any element whose raycastTarget is on (text,
images, buttons, input fields, and panels that draw a background or border; ADR 0069, 0385), not
only interactable UI. 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. It says where presses go, not whether the pointer is over the game: aiming by
hover can ignore it, and HUD elements that shouldn't block presses turn raycastTarget off.
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:133
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:137
number = 0
boolean
static getMouseButtonUp(button?): boolean;Defined in: src/engine/input/Input.ts:141
number = 0
boolean
static requestHidGamepads(): Promise<number>;Defined in: src/engine/input/Input.ts:194
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