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

createHotkeyAttachment

Call Signature

ts
function createHotkeyAttachment<T>(
   hotkey, 
   callback, 
options?): Attachment<HTMLElement>;
function createHotkeyAttachment<T>(
   hotkey, 
   callback, 
options?): Attachment<HTMLElement>;

Defined in: packages/svelte-hotkeys/src/createHotkey.svelte.ts:94

Create an attachment for an element-scoped hotkey: a chord, a sequence, or an app hotkey that listens on the attached element.

Type Parameters

T

T extends AppHotkey<string, HotkeyChord | HotkeySequence | null>

Parameters

hotkey

MaybeGetter<T>

callback

HotkeyCallback

options?

MaybeGetter<CreateAppHotkeyOptions<T>>

Returns

Attachment<HTMLElement>

Example

svelte
<script lang="ts">
  const saveKey = createHotkeyAttachment('Mod+S', () => save())
</script>

<div tabindex="0" {@attach saveKey}>Editor content</div>
<script lang="ts">
  const saveKey = createHotkeyAttachment('Mod+S', () => save())
</script>

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

Call Signature

ts
function createHotkeyAttachment<T>(
   hotkey, 
   callback, 
options?): Attachment<HTMLElement>;
function createHotkeyAttachment<T>(
   hotkey, 
   callback, 
options?): Attachment<HTMLElement>;

Defined in: packages/svelte-hotkeys/src/createHotkey.svelte.ts:99

Create an attachment for an element-scoped hotkey: a chord, a sequence, or an app hotkey that listens on the attached element.

Type Parameters

T

T extends RegisterableHotkey

Parameters

hotkey

MaybeGetter<T>

callback

HotkeyCallback<HotkeyCallbackContextFor<T>>

options?

MaybeGetter<AdapterOptionsFor<T, CreateHotkeyTarget>>

Returns

Attachment<HTMLElement>

Example

svelte
<script lang="ts">
  const saveKey = createHotkeyAttachment('Mod+S', () => save())
</script>

<div tabindex="0" {@attach saveKey}>Editor content</div>
<script lang="ts">
  const saveKey = createHotkeyAttachment('Mod+S', () => save())
</script>

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