Input API
typescript
import {
InputManager,
LocalMultiplayerManager,
GamepadButtons,
GamepadAxes,
} from "quantum-forge/input";InputManager
Constructor
typescript
new InputManager(options?: {
logger?: LoggerInterface;
gamepadIndex?: number; // -1 = no gamepad (default for multiplayer slots)
})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
typescript
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
typescript
input.destroy(); // removes all event listenersLocalMultiplayerManager
Constructor
typescript
new LocalMultiplayerManager(options: {
players: number;
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
typescript
mp.on("gamepad-assigned", ({ playerIndex, gamepadId }) => { /* ... */ });
mp.on("gamepad-disconnected", ({ playerIndex }) => { /* ... */ });GamepadButtons
A, B, X, Y, LB, RB, LT, RT, Back, Start,
LeftStick, RightStick, DpadUp, DpadDown, DpadLeft, DpadRightGamepadAxes
LeftStickX, LeftStickY, RightStickX, RightStickY