Keyboard
API docsimport { hotkey, pressed, formatHint } from "@joknoll/svelte-attach/key";Bind a shortcut
Shortcuts work without focus. By default, they're ignored in text fields.
<button {@attach hotkey("f")}>❤️ Like</button>Hold to repeat
Hold an arrow key or H, J, K, or L.
<button
{@attach hotkey(["arrowup", "k"], {
ignoreRepeat: false,
pressedClass: "is-pressed",
})}
onclick={() => move(0, -1)}
>↑</button>Shortcut hints
"shift"- Shift
"mod+enter"- Ctrl + Enter
"alt+arrowup"- Alt + Up
["j", "arrowdown"]- J / Down
<kbd {@attach pressed("mod+enter")}>{formatHint("mod+enter")}</kbd>Disable a shortcut
Press T to toggle the shortcut. Next stays clickable.
<button {@attach enabled && hotkey("n")}>Next</button>