Custom Sources
The input manager delegates to registered InputSource implementations when evaluating bindings. You can implement this interface to provide another backend for supported binding types. Browser gamepads are supported by the built-in GamepadInputSource.
InputSource Interface
Section titled “InputSource Interface”import type { InputSource, ButtonInput, AxisInput, DualAxisInput } from '@shell/input-manager';
class CustomInputSource implements InputSource { readonly id = 'custom';
poll(): void { // Optionally snapshot frame-based input once per frame }
hasActivity(): boolean { // Return true for fresh input that should make this source active }
isAvailable(): boolean { // Optional; unavailable active sources fall back automatically }
handles(input: ButtonInput | AxisInput | DualAxisInput): boolean { // return true for input types this source can handle }
isButtonPressed(input: ButtonInput): boolean { /* ... */ } isButtonJustPressed(input: ButtonInput): boolean { /* ... */ } isButtonJustReleased(input: ButtonInput): boolean { /* ... */ }
getAxis(input: AxisInput): number { /* ... */ }
getDualAxis(input: DualAxisInput): { x: number; y: number } { /* ... */ }}Registering a Source
Section titled “Registering a Source”Register it on the world’s inputSources resource:
world.get('inputSources').register(new CustomInputSource());InputSourceRegistry
Section titled “InputSourceRegistry”| Member | Description |
|---|---|
register(source) | Add a source (ignored if id already exists) |
unregister(id) | Remove a source by id |
poll() | Poll sources and update last-active selection |
sources | Readonly array of registered sources |
evaluationSources | Sources allowed by the configured selection policy |
activeSourceId | Currently selected source |
activeSourceChanged | Whether selection changed during the latest poll |
setActiveSource(id) | Explicitly select a registered, available source |
hasActivity() is optional for compatibility, but a custom source must implement it to participate
in automatic last-active selection. isAvailable() defaults to true when omitted.
Built-in Source
Section titled “Built-in Source”The built-in DomInputSource handles keyboard and pointer inputs. GamepadInputSource handles the browser Gamepad API. Both are registered automatically when InputManagerPlugin is added.
import { DomInputSource, GamepadInputSource } from '@shell/input-manager';DomInputSource reads from the keyboard and pointer resources provided by @shell/dom.
GamepadInputSource polls and snapshots navigator.getGamepads() once per frame.