Record real keyboard shortcuts for hotkey settings UIs. Captures live key combinations and ships with a useKeyboardShortcut hook to bind them.
Click the field, then press a combination like ⌘+Shift+K. Press Esc to cancel.
bunx --bun shadcn@latest add https://ui.ahmet.studio/r/shortcut-recorder
import { ShortcutRecorder, useKeyboardShortcut, } from "@/components/ui/shortcut-recorder"; export function Demo() { const [shortcut, setShortcut] = React.useState<string[]>(["Meta", "K"]); useKeyboardShortcut(shortcut, (e) => { e.preventDefault(); console.log("Shortcut fired!"); }); return <ShortcutRecorder value={shortcut} onChange={setShortcut} />; }
Most registries ship a static <Kbd> component. This component actually records shortcuts from real key events and gives you:
["Meta", "Shift", "K"]) you can persist anywhere.useKeyboardShortcut(tokens, handler) hook to bind a recorded shortcut directly.shortcutMatches(event, tokens) helper for custom listeners.forbidden prop.| Prop | Type | Default |
|---|---|---|
value | string[] | Required |
onChange | (value: string[]) => void | Required |
placeholder | string | "Press shortcut" |
allowSingleKey | boolean | false |
allowedModifiers | ("Meta" | "Control" | "Alt" | "Shift")[] | all |
forbidden | string[][] | [] |
maxKeys | number | 4 |
autoCommitOnBlur | boolean | true |
onConflict | (conflict: string[]) => void | undefined |
import { formatShortcut, shortcutMatches, useKeyboardShortcut, } from "@/components/ui/shortcut-recorder"; formatShortcut(["Meta", "K"]); shortcutMatches(event, ["Meta", "K"]); useKeyboardShortcut(["Meta", "K"], (e) => {});