Skip to content
synccn

Shortcut Recorder

New

Press 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-recorder

First 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 | null

    Controlled shortcut, written like "Mod+Shift+K". Mod means ⌘ on Mac and Ctrl elsewhere.

  • defaultValue
    string | null

    Default null

    Shortcut at first, when uncontrolled.

  • onValueChange
    (value: string | null) => void

    Called with the new shortcut, or null when cleared.

  • taken
    string[]

    Default []

    Shortcuts already in use, so clashes are flagged.

  • aria-label
    string

    Accessible name, e.g. "Open command menu".

  • className
    string

    Extra 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.

Helpers

  • lib/hooksuseControllable (works controlled or uncontrolled)
  • lib/utilscn (merges class names)

npm packages

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