Input API
import {
InputManager,
LocalMultiplayerManager,
GamepadButtons,
GamepadAxes,
} from "quantum-forge-engine/input";The subpath also exports the devices behind the manager, for games that want them directly: KeyboardDevice, MouseDevice, TouchDevice, GamepadDevice, VirtualJoystick, GestureRecognizer.
InputManager
Constructor
new InputManager(config?: {
bindings?: Binding[]; // initial bindings
deadZone?: number; // gamepad analog dead zone, 0-1 (default: 0.15)
preventDefaults?: boolean; // call preventDefault on browser input events (default: false)
gamepadIndex?: number; // which gamepad to read (default: 0, the first connected)
logger?: LoggerInterface;
})LocalMultiplayerManager passes -1 as a sentinel meaning "no gamepad yet" and assigns real indices as pads connect. Games constructing an InputManager themselves should leave gamepadIndex alone or set a real index.
Binding
| Method | Description |
|---|---|
bind(action, ...sources) | Map one or more sources to an action |
bindKey(code, action) | Shorthand for key binding |
bindButton(index, action) | Shorthand for gamepad button |
bindAxis(index, direction, action) | Shorthand for gamepad axis |
bindGesture(gesture, action) | Shorthand for gesture binding |
bindJoystick(name, axis, direction, action) | Shorthand for virtual joystick |
Querying
| Method | Returns | Description |
|---|---|---|
poll() | void | Must call every frame before queries |
isActionDown(action) | boolean | Held down (continuous) |
isActionJustPressed(action) | boolean | True only on press frame |
isActionJustReleased(action) | boolean | True only on release frame |
getActionValue(action) | number | 0–1 analog value |
getActiveDevice() | string | "keyboard", "mouse", "touch", "gamepad" |
getPointerPosition() | {x, y} | Client coordinates |
getCanvasPointerPosition(canvas) | {x, y} | Canvas-relative coordinates |
Events
const unsub = input.on(action, handler); // fires on press edge
unsub(); // unsubscribeTouch
| Method | Description |
|---|---|
addTouchZone(zone) | Register a named zone { name, x, y, w, h } (0–1 normalized) |
addJoystick(config) | Register virtual joystick { name, zone, radius?, deadZone?, dynamic? } |
getJoystickState(name) | Returns { active, x, y, magnitude } or null |
getGestures() | Returns array of recognized gestures this frame |
getPinchState() | Returns { active, scale, rotation } |
configureGestures(options) | Set thresholds for gesture recognition |
Cleanup
input.destroy(); // removes all event listenersLocalMultiplayerManager
Constructor
new LocalMultiplayerManager(config: {
players: number; // number of player slots
playerConfigs?: Partial<InputManagerConfig>[]; // per-slot overrides, by player index
autoAssign?: boolean; // auto-assign gamepads as they connect (default: true)
deadZone?: number; // dead zone for every slot (default: 0.15)
logger?: LoggerInterface;
})Methods
| Method | Description |
|---|---|
getPlayer(index) | Returns InputManager for player (or null) |
getPlayers() | Returns all { index, input } slots |
bindAll(action, ...sources) | Bind to all players' InputManagers |
pollAll() | Call poll() on all players |
assignGamepad(playerIndex, gamepadIndex) | Manual gamepad assignment |
unassignGamepad(playerIndex) | Remove gamepad from player |
destroy() | Cleanup all InputManagers |
Events
mp.on("gamepad-assigned", ({ playerIndex, gamepadId }) => { /* ... */ });
mp.on("gamepad-disconnected", ({ playerIndex }) => { /* ... */ });Event types: "gamepad-connected", "gamepad-disconnected", "gamepad-assigned", "gamepad-unassigned". In the current implementation a connection emits only "gamepad-assigned"; "gamepad-connected" is declared in the type union but not yet emitted. Every handler receives { type, playerIndex, gamepadIndex, gamepadId }. on() returns an unsubscribe function.
GamepadButtons
A, B, X, Y, LB, RB, LT, RT, Back, Start,
LeftStick, RightStick, DpadUp, DpadDown, DpadLeft, DpadRightGamepadAxes
LeftStickX, LeftStickY, RightStickX, RightStickY