Docs
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
OpenRouter
Neon
WorkOS
Clerk
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
Hotkeys API Reference
Hotkey Sequence API Reference
Key hold & held keys API Reference
Hotkey Recorder API Reference
Hotkey Sequence Recorder API Reference
Normalization & format API Reference
Key hold & held keys API Reference

createKeyHold

Function: createKeyHold()

ts
function createKeyHold(key): () => boolean;
function createKeyHold(key): () => boolean;

Defined in: createKeyHold.ts:46

SolidJS primitive that returns whether a specific key is currently being held.

This primitive uses useStore from @tanstack/solid-store to subscribe to the global KeyStateTracker and uses a selector to determine if the specified key is held.

Parameters

key

The key to check (e.g., 'Shift', 'Control', 'A') - can be an accessor function

IndividualKey | () => IndividualKey

Returns

Signal accessor that returns true if the key is currently held down

ts
(): boolean;
(): boolean;

Returns

boolean

Examples

tsx
function ShiftIndicator() {
  const isShiftHeld = createKeyHold('Shift')

  return (
    <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>
      {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}
    </div>
  )
}
function ShiftIndicator() {
  const isShiftHeld = createKeyHold('Shift')

  return (
    <div style={{ opacity: isShiftHeld() ? 1 : 0.5 }}>
      {isShiftHeld() ? 'Shift is pressed!' : 'Press Shift'}
    </div>
  )
}
tsx
function ModifierIndicators() {
  const ctrl = createKeyHold('Control')
  const shift = createKeyHold('Shift')
  const alt = createKeyHold('Alt')

  return (
    <div>
      <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>
      <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>
      <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>
    </div>
  )
}
function ModifierIndicators() {
  const ctrl = createKeyHold('Control')
  const shift = createKeyHold('Shift')
  const alt = createKeyHold('Alt')

  return (
    <div>
      <span style={{ opacity: ctrl() ? 1 : 0.3 }}>Ctrl</span>
      <span style={{ opacity: shift() ? 1 : 0.3 }}>Shift</span>
      <span style={{ opacity: alt() ? 1 : 0.3 }}>Alt</span>
    </div>
  )
}