Skip to content

Input Manager

The @shell/input-manager package maps raw inputs (keyboard, mouse, gamepad) to named actions and reads their state each frame. It works as both a global resource and a per-entity component, and supports pluggable input sources for custom backends.

Register InputManagerPlugin on the world. It depends on InputPlugin from @shell/dom (added automatically).

import { InputManagerPlugin, InputMapData, wasd } from '@shell/input-manager';
world.addPlugin(InputManagerPlugin);

To enable a global input map (useful for single-player or UI-level input), pass a config:

world.addPlugin(
InputManagerPlugin.config({
globalMap: new InputMapData()
.bind('move', { type: 'dualAxis', source: wasd() })
.bind('jump', { type: 'button', source: { kind: 'key', code: 'Space' } }),
}),
);

This binds inputMap and actionState as world resources and enables the run condition helpers.