@fogrexon/glyph-arena-input

Keyboard and pointer input snapshot from an EventTarget. See also package README.

Exports

Generated from the package's source when the docs are built — do not edit this table by hand.

NameKind
Inputtype
InputSnapshottype
PointerStatetype
createInputfunction

createInput()

const input = createInput();

input.attach(target);  // EventTarget (e.g. window, canvas)
input.detach();
input.snapshot();
input.dispose();

Methods

InputSnapshot

FieldTypeDescription
keysReadonlySet<string>Down now, or pressed since the previous snapshot() (the latch)
pointersreadonly PointerState[]Down now, or landed since the previous snapshot() (the latch)

PointerState

FieldTypeDescription
idnumberpointerId
xnumberRaw clientX
ynumberRaw clientY
buttonsnumberbuttons bitmask

Attach behavior

The press latch

A loop samples once per frame, so a keydown and keyup that both land between two samples used to be invisible, and every mechanical test had to hold a key for 150 ms. A press that ends before the frame runs is now reported for that one frame, so actions.pressed() still sees the edge. It is one frame, not a hold: snapshot() consumes the latch, so call it once per frame. Auto-repeat is not a second press.

The pointer latch

A click or a tap that lands and lifts between two frames used to be invisible — the title screen never started, a menu item never fired. A press that ended before the frame runs now appears in pointers for that one frame, at the position it landed at, so createTouchControls and any menu handler see it. A pointer that is still down answers with its live position and is listed once. Same latch as the keys, same one-frame life.

State clearing

dispose()

Detaches listeners, clears state, and prevents further listener registration. Subsequent events on a previously attached target are not tracked. attach() after dispose() is a no-op.