# Kbd press

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

Also called: keyboard shortcut animation, key press animation.

Example: Shortcuts that press. Keycaps go down in the order a hand presses them, modifier first, whenever the shortcut fires. The real keys work too. Preview: https://chatcn.dev/preview/kbd-press-demo

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

```bash
npx 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

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

Source: https://chatcn.dev/docs/components/kbd-press