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

createHotkeysAttachment

ts
function createHotkeysAttachment(hotkeys, commonOptions?): Attachment<HTMLElement>;
function createHotkeysAttachment(hotkeys, commonOptions?): Attachment<HTMLElement>;

Defined in: packages/svelte-hotkeys/src/createHotkeys.svelte.ts:152

Create an attachment for element-scoped hotkeys: chords, sequences, and app hotkeys listen on the attached element.

Parameters

hotkeys

MaybeGetter<readonly CreateHotkeyDefinition[]>

commonOptions?

MaybeGetter<CreateHotkeyCommonOptions> = {}

Returns

Attachment<HTMLElement>

Example

svelte
<script lang="ts">
  const editorKeys = createHotkeysAttachment([
    { hotkey: 'Mod+S', callback: () => save() },
    { hotkey: ['G', 'G'], callback: () => scrollToTop() },
  ])
</script>

<div tabindex="0" {@attach editorKeys}>Editor content</div>
<script lang="ts">
  const editorKeys = createHotkeysAttachment([
    { hotkey: 'Mod+S', callback: () => save() },
    { hotkey: ['G', 'G'], callback: () => scrollToTop() },
  ])
</script>

<div tabindex="0" {@attach editorKeys}>Editor content</div>