idle
SourceA snapshot with no buttons down, for initializing an input resource before the first capture.
Browser
Mouse and pen input over one element: position and button edges. Touches are ignored by default; on-screen touch controls are Touch.
Games that aim with the mouse read one snapshot per update, like keyboard actions. The module owns the browser plumbing: element-relative coordinates, press/release edges that survive clicks shorter than one frame, pointer capture so a release outside the element is still seen, suppressing the context menu, clearing buttons on window blur, and listener cleanup. It does not know about the ECS; InputCapture.system(...) copies snapshots from a service into a resource, directly or through an adapter that merges pointer and keyboard snapshots.
Positions are in CSS pixels relative to the element's top-left corner. Converting them into world coordinates (camera, zoom, projection) is game code.
const pointer = Pointer.track(canvas, window)
// Once per update:
const snapshot = pointer.snapshot()
aimAt(snapshot.position)
if (snapshot.primary.held) fire()
// On teardown:
pointer.dispose()
For tests, replays, and headless runs, scripted(...) plays a timeline of moves, presses, and releases, and recording(...) wraps a live pointer to capture the timeline a session produced. parseTimeline(...) validates a timeline loaded from JSON.
A snapshot with no buttons down, for initializing an input resource before the first capture.
trackStarts tracking the pointer over target. blurHost (usually window) releases held buttons when the page loses focus.
scriptedPlays timeline: before the snapshot at index frame, every entry for that frame is applied. Buttons stay held from their press until their release. The scripted pointer is always over the element.
recordingWraps pointer and records, for every snapshot, the position when it moved and the buttons pressed and released since the previous one.
parseTimelineValidates untrusted data, such as a parsed JSON file, as a pointer timeline: an array of entries with a non-negative integer frame, an optional finite move, and optional press/release arrays of buttons.
A snapshot with no buttons down, for initializing an input resource before the first capture.
Starts tracking the pointer over target. blurHost (usually window) releases held buttons when the page loses focus.
Plays timeline: before the snapshot at index frame, every entry for that frame is applied. Buttons stay held from their press until their release. The scripted pointer is always over the element.
Wraps pointer and records, for every snapshot, the position when it moved and the buttons pressed and released since the previous one.
Validates untrusted data, such as a parsed JSON file, as a pointer timeline: an array of entries with a non-negative integer frame, an optional finite move, and optional press/release arrays of buttons.