Utility·phaserthree·v1.0.0·MIT
Input Manager
Engine-agnostic input action mapper. Map logical actions ('jump', 'left') to keyboard bindings and query state without coupling gameplay code to the DOM keyboard API.
#input#keyboard#actions
Install
npx gamecn add input-managerSource preview
Compatibility
| Engines | phaser >=3.80.0 <4.0.0three >=0.160.0 |
| Frameworks | vanilla, react |
| Languages | typescript |
| Bundlers | vite |
Files installed
- {src}/utilities/InputManager.ts
- docs/gamecn/input-manager.md(docs)
Notes
Usage
import { InputManager } from "@/utilities/InputManager";
const input = new InputManager({
bindings: {
jump: "Space",
left: ["ArrowLeft", "KeyA"],
right: ["ArrowRight", "KeyD"],
up: ["ArrowUp", "KeyW"],
down: ["ArrowDown", "KeyS"],
},
});
// In your update loop:
function update(): void {
if (input.wasPressed("jump")) player.jump();
const move = input.axis("left", "right", "up", "down");
player.move(move.x, move.y);
input.endFrame(); // clears edge events
}
// On scene/component teardown:
input.dispose();API
| Method | Description |
|---|---|
isDown(action) |
True while held. |
wasPressed(action) |
True on the frame of the press (cleared by endFrame). |
wasReleased(action) |
True on the frame of the release. |
axis(left, right, up, down) |
2D {x, y} in {-1, 0, 1}. |
endFrame() |
Call once per tick. |
dispose() |
Remove DOM listeners. |
Notes
- Uses
KeyboardEvent.code(layout-independent), notkey. preventDefaultistrueby default — pass{ preventDefault: false }to disable.- Cross-engine: works inside Phaser scenes, R3F components, vanilla Three, or DOM-only games.
Related
- Mobile JoystickComponent
On-screen virtual joystick for touch input. Renders to a DOM element; exposes a 2D vector for gameplay. Engine-agnostic.
- Audio ManagerSystem
Web Audio-based SFX and music manager with named buses, volume control, and pluggable buffer loading. Engine-agnostic.
- Dialogue SystemSystem
Branching JSON-driven dialogue runner with choices and variables. Engine-agnostic — bring your own UI renderer.
- Save LoadUtility
Type-safe localStorage-backed save system with versioning and migrations. Engine-agnostic.