Skip to content
Key hold & held keys API Reference

createHeldKeys

ts
function createHeldKeys(): () => string[];

Defined in: createHeldKeys.ts:25

SolidJS primitive that returns a signal of currently held keyboard keys.

This primitive subscribes to the global KeyStateTracker and updates whenever keys are pressed or released.

Returns

Signal accessor for array of currently held key names

() => string[]

Example

tsx
function KeyDisplay() {
  const heldKeys = createHeldKeys()

  return (
    <div>
      Currently pressed: {heldKeys().join(' + ') || 'None'}
    </div>
  )
}