Shortcut Recorder
NewPress keys to set a keyboard shortcut. Platform symbols, clash warnings and a portable "Mod+K" value with a matcher.
Search
Toggle sidebar
Press Ctrl K anywhere: triggered 0 times
Installation
$ pnpm dlx shadcn@latest add @synccn/shortcut-recorderFirst time in this project? Connect synccn with one command.
Usage
import { ShortcutRecorder, formatShortcut, matchesShortcut } from "@/components/ui/shortcut-recorder";<ShortcutRecorder value={combo} onValueChange={setCombo} taken={used} />API reference
Generated from the component's TypeScript types, so it always matches the code.
ShortcutRecorder
Click and press keys to set a keyboard shortcut. Shows platform symbols, warns about clashes and shortcuts without a modifier, and gives you a portable "Mod+K" string.
- value
string | nullControlled shortcut, written like "Mod+Shift+K". Mod means ⌘ on Mac and Ctrl elsewhere.
- defaultValue
string | nullDefault
nullShortcut at first, when uncontrolled.
- onValueChange
(value: string | null) => voidCalled with the new shortcut, or null when cleared.
- taken
string[]Default
[]Shortcuts already in use, so clashes are flagged.
- aria-label
stringAccessible name, e.g. "Open command menu".
- className
stringExtra classes for the root element.
formatShortcut
Turns "Mod+Shift+K" into the symbols for the person's platform: ⌘⇧K on a Mac, Ctrl+Shift+K elsewhere.
Takes no props.
matchesShortcut
True when a keyboard event matches a shortcut like "Mod+K".
Takes no props.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for Keyboard, X
Used by
Keyboard
- EnterorSpaceStart recording
- EscCancel recording
- BackspaceorDeleteClear the shortcut
Accessibility
- The button's label reads out the current shortcut, and warnings are announced politely.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA attributes: aria-label, aria-live
- Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Escape, Backspace, Delete
- Shows a visible focus ring for keyboard users
- Announces changes to screen readers