Browser

Pointer

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.

Examples

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.

Functions

idle

Source

A snapshot with no buttons down, for initializing an input resource before the first capture.

track

Source

Starts tracking the pointer over target. blurHost (usually window) releases held buttons when the page loses focus.

scripted

Source

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.

recording

Source

Wraps pointer and records, for every snapshot, the position when it moved and the buttons pressed and released since the previous one.

parseTimeline

Source

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.