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
API Reference
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

getIsKeyHeld

Function: getIsKeyHeld()

ts
function getIsKeyHeld(key): SvelteHeldKeyState;

Defined in: packages/svelte-hotkeys/src/getIsKeyHeld.svelte.ts:66

Svelte function that returns reactive access to whether a specific key is currently being held.

This function uses the global KeyStateTracker and updates whenever keys are pressed or released.

Parameters

key

IndividualKey

The key to check (e.g., 'Shift', 'Control', 'A')

Returns

SvelteHeldKeyState

Object with a reactive held property

Examples

svelte
<script>
  import { getIsKeyHeld } from '@tanstack/svelte-hotkeys'

  const isShiftHeld = getIsKeyHeld('Shift')
</script>

<div>
  {isShiftHeld.held ? 'Shift is pressed!' : 'Press Shift'}
</div>
svelte
<script>
  import { getIsKeyHeld } from '@tanstack/svelte-hotkeys'

  const isCtrlHeld = getIsKeyHeld('Control')
  const isShiftHeld = getIsKeyHeld('Shift')
  const isAltHeld = getIsKeyHeld('Alt')
</script>

<div>
  <span style:opacity={isCtrlHeld.held ? 1 : 0.3}>Ctrl</span>
  <span style:opacity={isShiftHeld.held ? 1 : 0.3}>Shift</span>
  <span style:opacity={isAltHeld.held ? 1 : 0.3}>Alt</span>
</div>