Skip to content
Sign upGet access
MicrointeractionsKbd pressMenu

Kbd press

Keyboard shortcuts that press: the caps go down modifier first, the key a beat later, whenever the shortcut fires.

Keycaps go down in the order a hand presses them, modifier first, whenever the shortcut fires. The real keys work too.

Shortcut hints are usually flat labels. These caps sit proud of the surface with a little depth, and when the shortcut fires they go down in the order a hand presses them, modifiers first and the key a beat later, then come back up in reverse. Pass listen and typing the combination anywhere presses them; mod reads as Command on Apple devices and Ctrl elsewhere.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/kbd-press.json

Usage

tsx
import { KbdPress } from "@/components/ui/chatcn/kbd-press"

<KbdPress keys={["mod", "k"]} listen onTrigger={openSearch} />

Props

PropTypeNotes
keysstring[]mod, shift, alt, enter, escape and arrows get symbols
listenbooleanPress when the combination is typed anywhere
onTrigger(event: KeyboardEvent) => voidFires on that combination
pressnumberIncrement to play a press from code

Accessibility

  • role="img" named with the spelled out keys ("Ctrl K").
  • Listening reacts to the page's keys; call preventDefault in onTrigger when you take the shortcut over.

Motion

  • Each cap travels 2 px with its shadow collapsing, 30 ms apart; modifiers hold longest.
  • Reduced motion: a short opacity dip instead of the press.