Skip to content
Sign upPro
FramesKeyboardMenu

Keyboard

A laptop keyboard drawn from above with every legend. Keys travel down as a line types along, shift held for capitals, or light from real key presses; a shortcut can be ringed in the accent.

A request typed into a field while the keys press under it, shift held for the capital. Loops.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/keyboard.json

Usage

tsx
import { Keyboard, useTypeAlong } from "@/components/ui/chatcn/keyboard"

function Demo() {
  const t = useTypeAlong("Summarize the last five support tickets", { loop: true })
  return (
    <div ref={t.ref}>
      <MyField value={t.typed} />
      <Keyboard pressed={t.pressed} />
    </div>
  )
}

// Teach a shortcut
<Keyboard highlight={["MetaLeft", "KeyK"]} />

Keys are named by KeyboardEvent.code (KeyA, ShiftLeft, MetaLeft, Space), so pressed, highlight and real key events need no table. The layout and legends come from chatcn-keyboard: US ANSI, 14.5 keys wide, with letters centred on their cap height, shifted pairs stacked, words on their own side, and modifier and function glyphs placed by their ink, not their box.

A press is physical: the cap slides down over its own skirt in 100 ms, so its drop shortens to nothing, and comes back up in 160 ms. Legend strength follows the rendered cap size: under about 500 px wide the words and function labels step aside and the letters and glyphs stay. Under reduced motion a pressed cap only brightens.

useTypeAlong(text, { cps, startDelay, loop, paused }) types at 11 characters a second, each gap 35% faster or slower from a seeded generator, with a breath after commas and full stops, a longer one after a new line and now and then a pause between words. Capitals hold the shift on the other hand from just before the letter to just after, and a run of capitals keeps it down. It returns typed, pressed, done, restart and a ref that pauses it off screen. Under reduced motion the text is complete at once.

Examples

A shortcut ringed, keys pressed, backlit, pale caps, PC modifiers, angled, without the function row, and at 320 px.

A shortcut ringed, keys pressed, backlit, pale caps, PC modifiers, angled, without the function row and at 320 px.

Props

PropTypeNotes
widthnumberDefault 640; capped at the container width
variantdark | lightDark caps on silver, or pale caps; default dark
viewflat | angledAngled leans it back 38 degrees with side walls
modifiersmac | pcThe bottom row; default mac
fnRowfull | half | noneDefault full
pressedstring[]Keys drawn pressed, by code
highlightstring[]Keys ringed in the accent; also names them for screen readers
listenbooleanMirror the real keyboard; never prevents default
backlightnumber0 to 1; legends glow and light shows in the gaps
onKeyPress(code) => voidA pointer press on a key
labelstringAccessible name; default Keyboard

The keyboard is a picture (role="img"): its keys are not focusable. It never mirrors on a right to left page, and in forced colors each cap keeps an outline.