Kbd press
Keyboard shortcuts that press: the caps go down modifier first, the key a beat later, whenever the shortcut fires.
On this page
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
Usage
import { KbdPress } from "@/components/ui/chatcn/kbd-press"
<KbdPress keys={["mod", "k"]} listen onTrigger={openSearch} />Props
| Prop | Type | Notes |
|---|---|---|
keys | string[] | mod, shift, alt, enter, escape and arrows get symbols |
listen | boolean | Press when the combination is typed anywhere |
onTrigger | (event: KeyboardEvent) => void | Fires on that combination |
press | number | Increment 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
preventDefaultinonTriggerwhen 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.