Shortcut Recorder

Checks a newly recorded keyboard shortcut against browser and OS reserved keys and the app's own bindings before it's saved.

StopsShortcut clashes with Ctrl+W

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/shortcut-recorder.json

The files land in your project. They're yours to edit.

Usage

shortcut-recorder-usage.tsx
import { ShortcutRecorder } from "@/components/ui/shortcut-recorder"

return <ShortcutRecorder label="Quick add" defaultValue="Mod+Q" bindings={bindings} platform="windows" />

What it catches

  • Combos the browser or OS keeps for itself, blocked from saving
  • Clashes with the app's existing bindings, naming the action
  • Keys that need AltGr on some keyboard layouts
  • Read-back for both Mac and Windows/Linux

Props

ShortcutRecorder props
PropTypeDefault
label

Visible label.

string"Shortcut"
value

Controlled shortcut in canonical form ("Mod+Shift+K"), or null for none.

string | null—
defaultValue

Initial shortcut when uncontrolled.

string | nullnull
onValueChange

Called with the saved shortcut, or null when cleared.

(value: string | null) => void—
bindings

The app's existing shortcuts; a clash names the action. Leave out the one being edited.

ShortcutBinding[][]
platform

Platform to read back first. Detected from the browser when left out.

Platform—
placeholder

Shown while empty.

string"Click to record"
recordingLabel

Shown while recording with nothing held.

string"Press a shortcut…"
recordingHint

Hint while recording.

string"Esc cancels · Backspace clears"
useAnywayLabel

Saves a shortcut that only has warnings.

string"Use anyway"
tryAgainLabel

Label of the try-again button after a blocked combo.

string"Try again"
clearLabel

Accessible label of the clear button.

string"Clear shortcut"
macLabel

Platform names in the readback.

string"Mac"
pcLabel

Label for the Windows/Linux read-back.

string"Windows/Linux"
formatIssue

Rewrites an issue's text, e.g. to translate it. `issue.problem` says which check fired; `keys` is the canonical shortcut.

(issue: ShortcutIssue, keys: string) => string—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Recorder is a button with aria-pressed while recording, labelled and described by its status
  • Tab or Escape (with no modifiers) stops recording; Backspace/Delete clears
  • Status in a polite live region; blocking issues use role=alert
  • Clear button has an aria-label

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • The reserved list covers common browsers and OSes; extensions and custom OS shortcuts are unknown
  • Layout warnings are heuristic

What it stops

Shortcut clashes with Ctrl+W

Also known as

keyboard shortcut · hotkey · keybinding · shortcut recorder · cmd k · settings · accessibility · mac windows

Field type

Dependencies

Pairs well with