TanStack
Hotkeys API Reference

createHotkeyAttachment

Function: createHotkeyAttachment()

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

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

Create an attachment for element-scoped hotkeys.

Parameters

hotkey

MaybeGetter<RegisterableHotkey>

callback

HotkeyCallback

options

MaybeGetter<CreateHotkeyOptions> = {}

Returns

Attachment<HTMLElement>

Example

svelte
<script lang="ts">
  import { createHotkeyAttachment } from '@tanstack/svelte-hotkeys'

  let count = $state(0)
  const saveHotkey = createHotkeyAttachment('Mod+S', () => {
    count++
  })

</script>

<div tabindex="0" {@attach saveHotkey}>
  Count: {count}
</div>