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
App Hotkeys API Reference
Key hold & held keys API Reference
Hotkey Recorder API Reference
Normalization & format API Reference
Hotkeys API Reference

setHotkeysContext

ts
function setHotkeysContext(options?): HotkeysContextValue;
function setHotkeysContext(options?): HotkeysContextValue;

Defined in: packages/svelte-hotkeys/src/HotkeysCtx.ts:89

Sets the hotkeys context for descendants. HotkeysProvider calls this; call it directly in a component's script instead of rendering the provider.

Nest contexts to create hotkey scopes. A nested context inherits app hotkeys and merges default options. With scope, its hotkeys fire only while the component is mounted and enabled; with exclusive, only its hotkeys fire.

Parameters

options?

HotkeysContextOptions = {}

Returns

HotkeysContextValue

Example

svelte
<script lang="ts">
  setHotkeysContext({
    appHotkeys,
    customHotkeys: JSON.parse(localStorage.getItem('hotkeys') ?? '{}'),
    onCustomHotkeysChange: (custom) =>
      localStorage.setItem('hotkeys', JSON.stringify(custom)),
  })
</script>
<script lang="ts">
  setHotkeysContext({
    appHotkeys,
    customHotkeys: JSON.parse(localStorage.getItem('hotkeys') ?? '{}'),
    onCustomHotkeysChange: (custom) =>
      localStorage.setItem('hotkeys', JSON.stringify(custom)),
  })
</script>