TanStack
Key hold & held keys API Reference

KeyStateTrackerState

Defined in: key-state-tracker.ts:10

State interface for the KeyStateTracker.

Properties

heldCodes

ts
heldCodes: Record<string, string>;

Defined in: key-state-tracker.ts:19

Map from normalized key name to the physical event.code (e.g. "KeyA", "ShiftLeft"). Useful for debugging which physical key was pressed.


heldKeys

ts
heldKeys: string[];

Defined in: key-state-tracker.ts:14

Array of currently held key names (normalized, e.g. "Control", "A").


locks

ts
locks: Record<LockKey, boolean | null>;

Defined in: key-state-tracker.ts:26

Whether each lock key is on. null while no browser event has reported it: until the user presses a key, clicks, or moves the mouse, after the window loses focus or the page is hidden, and always for Num Lock and Scroll Lock on macOS and iOS, where browsers don't report them.