Skip to content

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.

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 } {
/* ... */
}
}

Register it on the world’s inputSources resource:

world.get('inputSources').register(new CustomInputSource());
MemberDescription
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
sourcesReadonly array of registered sources
evaluationSourcesSources allowed by the configured selection policy
activeSourceIdCurrently selected source
activeSourceChangedWhether 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.

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.