A sequence is a hotkey made of chords pressed one after another, like G then H to go home, VS Code's Ctrl+K then Ctrl+C, or Vim commands.
createHotkey and createHotkeys accept sequences just like chords, with the same options, targets, enabled, and meta. This guide covers what's specific to sequences.
Pass an array of chords to createHotkey:
import { createHotkey } from '@tanstack/solid-hotkeys'
function App() {
// Press G, then H
createHotkey(['G', 'H'], () => goHome())
return <main>...</main>
}Mix chords and sequences freely in createHotkeys:
createHotkeys([
{ hotkey: 'Mod+K', callback: () => openSearch() },
{ hotkey: ['G', 'H'], callback: () => goHome() },
{ hotkey: ['G', 'S'], callback: () => goToSettings() },
])In the callback, context.kind is 'sequence' and context.parsedSequence holds each parsed step:
createHotkey(['Mod+K', 'Mod+C'], (event, context) => {
console.log(context.hotkey) // ['Mod+K', 'Mod+C']
console.log(context.parsedSequence.map((step) => step.key)) // ['K', 'C']
})Every step uses the same chord syntax: strings, physical codes, or RawHotkeyChord objects.
createHotkey(['G', 'H'], () => goHome()) // G then H on any layout
createHotkey(['[KeyG]', '[KeyH]'], () => goHome()) // Physical G and H positions
createHotkey(['Mod+K', 'Mod+C'], () => commentLine()) // Command+K then Command+C on macOS
createHotkey(['G', 'Shift+G'], () => scrollToBottom()) // Separate modifiers per step
createHotkey(['Shift+R', 'Shift+T'], () => runTests()) // Modifiers can stay held between steps
createHotkey([{ key: 'K', mod: true }, 'C'], () => openChat()) // Mix objects and stringsA single-item array like ['Escape'] normalizes to a plain chord 'Escape'. See Write a chord as a string or an object.
Each step must follow the previous one within timeout milliseconds (1000 by default). Set timeout per sequence or globally via HotkeysProvider:
createHotkey(['D', 'D'], () => deleteLine(), { timeout: 500 }) // Snappier double-tap
createHotkey(['G', 'G'], () => scrollToTop(), { timeout: 2000 }) // More forgiving gap<HotkeysProvider defaultOptions={{ hotkey: { timeout: 1500 } }}>
<App />
</HotkeysProvider>While the user types through a sequence:
See Sequences allow 1 second between steps for details.
Most options from Hotkey options behave identically, with a few sequence-specific details:
| Pattern | Example | Behavior |
|---|---|---|
| Shared prefix | ['D', 'D'] and ['D', 'W'] | Both track progress independently until the next key decides (no warning) |
| Prefix of a longer sequence | ['G', 'G'] and ['G', 'G', 'G'] | Shorter fires immediately on step 2, and longer fires on step 3 |
| Chord and sequence on same key | 'G' and ['G', 'G'] | First G fires the chord. Once a sequence is active, continuing keys belong to it |
createHotkeys([
{ hotkey: ['D', 'D'], callback: () => deleteLine() },
{ hotkey: ['D', 'W'], callback: () => deleteWord() },
{ hotkey: ['D', 'I', 'W'], callback: () => deleteInnerWord() },
])Sharing leading steps is expected and never triggers a duplicate warning. Two sequences are duplicates only if all steps match. See Handle duplicate hotkeys.
If one sequence is a strict prefix of another, such as ['G', 'G'] and ['G', 'G', 'G'], the shorter sequence fires immediately on the second G without waiting to see if a third follows. The third G fires ['G', 'G', 'G'], and a fourth fires ['G', 'G'] again.
Prefer non-overlapping sequences such as ['G', 'G'] and ['G', 'B']. App Hotkeys and Hotkey Recording (detectConflicts) treat prefix overlaps as conflicts.
Once a sequence is underway, a key that continues it belongs to the sequence and blocks any standalone chord on that key:
createHotkeys([
{ hotkey: 'C', callback: () => compose() }, // Standalone C
{ hotkey: ['G', 'C'], callback: () => goToContacts() }, // Pressing G then C won't trigger compose()
])By contrast, the first step doesn't block a chord on the same key because the user might just want the single key:
createHotkeys([
{ hotkey: 'G', callback: () => openGoMenu() }, // Runs on first G
{ hotkey: ['G', 'G'], callback: () => scrollToTop() }, // Runs on second G
])Timed-out, disabled, or input-ignored sequences never claim keys. Note that App Hotkeys and Hotkey Recording check conflicts more strictly and flag G versus ['G', 'H'] as colliding.
The function from createFormatForDisplay formats each step and joins them with spaces by default, customizable via sequenceSeparator:
formatForDisplay(['Mod+K', 'Mod+C'], { platform: 'mac' }) // '⌘ K ⌘ C'
formatForDisplay(['G', 'H'], { sequenceSeparator: ' then ' }) // 'G then H'See Formatting & Display for keycaps and layout options.
Because the first key of a sequence has no immediate effect, showing pending keys in a status banner (like VS Code after Ctrl+K) makes sequences discoverable. Read matchedStepCount from useHotkeyRegistrations:
import { Show } from 'solid-js'
import {
createFormatForDisplay,
createHotkeyRegistrations,
} from '@tanstack/solid-hotkeys'
import type { HotkeySequenceRegistrationView } from '@tanstack/solid-hotkeys'
function PendingKeys() {
const formatForDisplay = createFormatForDisplay()
const registrations = createHotkeyRegistrations()
const longest = () =>
registrations()
.filter(
(reg): reg is HotkeySequenceRegistrationView =>
reg.kind === 'sequence' && reg.matchedStepCount > 0,
)
.sort((a, b) => b.matchedStepCount - a.matchedStepCount)[0]
return (
<Show when={longest()}>
{(reg) => (
<p role="status">
<kbd>{formatForDisplay(reg().hotkey.slice(0, reg().matchedStepCount))}</kbd>{' '}
was pressed. Waiting for the next key.
</p>
)}
</Show>
)
}matchedStepCount resets automatically on completion, mismatch, or timeout, so the status clears itself. See Cheat Sheets for displaying full shortcut lists.
A sequence made only of letters, numbers, or symbols (like ['G', 'H']) is treated as a character-key shortcut under accessibility guidelines. Give users a way to turn it off via enabled or remap it with App Hotkeys. See Single-key shortcuts need an off switch.
createHotkeys([
{ hotkey: ['G', 'G'], callback: () => scrollToTop() },
{ hotkey: ['G', 'Shift+G'], callback: () => scrollToBottom() },
{ hotkey: ['D', 'D'], callback: () => deleteLine() },
{ hotkey: ['D', 'W'], callback: () => deleteWord() },
{ hotkey: ['C', 'I', 'W'], callback: () => changeInnerWord() },
])createHotkey(
[
'ArrowUp', 'ArrowUp',
'ArrowDown', 'ArrowDown',
'ArrowLeft', 'ArrowRight',
'ArrowLeft', 'ArrowRight',
'B', 'A',
],
() => enableEasterEgg(),
{ timeout: 2000 },
)To let users record sequences in settings, see Hotkey Recording. To match sequences outside the hotkey manager, see Match a sequence on your own.
Note
createHotkeySequence, createHotkeySequences, and createHotkeySequenceRecorder were removed in @tanstack/solid-hotkeys v0.14.0. Pass sequence arrays directly to createHotkey or createHotkeys, and pass maxSteps: Infinity to createHotkeyRecorder.