Docs
CodeRabbit
Cloudflare
Railway
SerpAPI
WorkOS
OpenRouter
AG Grid
Clerk
Netlify
Electric
Prisma
Unkey
Sentry
CodeRabbit
Cloudflare
Railway
SerpAPI
WorkOS
OpenRouter
AG Grid
Clerk
Netlify
Electric
Prisma
Unkey
Sentry
API Reference
Hotkeys API Reference
Hotkey Sequence API Reference
Key hold & held keys API Reference
Hotkey Recorder API Reference
Hotkey Sequence Recorder API Reference
Normalization & format API Reference
Hotkey Sequence API Reference

createHotkeySequenceAttachment

Function: createHotkeySequenceAttachment()

ts
function createHotkeySequenceAttachment(
   sequence, 
   callback, 
options): Attachment<HTMLElement>;
function createHotkeySequenceAttachment(
   sequence, 
   callback, 
options): Attachment<HTMLElement>;

Defined in: packages/svelte-hotkeys/src/createHotkeySequence.svelte.ts:151

Create an attachment for element-scoped keyboard sequences.

Parameters

sequence

MaybeGetter<HotkeySequence>

callback

HotkeyCallback

options

MaybeGetter<CreateHotkeySequenceOptions> = {}

Returns

Attachment<HTMLElement>

Example

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

  const vimKeys = createHotkeySequenceAttachment(['G', 'G'], () => {
    scrollToTop()
  })
</script>

<div tabindex="0" {@attach vimKeys}>
  Focus here and press g then g
</div>
<script lang="ts">
  import { createHotkeySequenceAttachment } from '@tanstack/svelte-hotkeys'

  const vimKeys = createHotkeySequenceAttachment(['G', 'G'], () => {
    scrollToTop()
  })
</script>

<div tabindex="0" {@attach vimKeys}>
  Focus here and press g then g
</div>