Docs
Cloudflare
Railway
CodeRabbit
OpenRouter
Clerk
SerpAPI
AG Grid
WorkOS
Netlify
Unkey
Electric
Sentry
Prisma
Cloudflare
Railway
CodeRabbit
OpenRouter
Clerk
SerpAPI
AG Grid
WorkOS
Netlify
Unkey
Electric
Sentry
Prisma
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;
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>
<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>
<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>