Skip to content
Hotkeys API Reference

createHotkeyAttachment

Call Signature

ts
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>

Call Signature

ts
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>