asafefe.dev
Lab

Lab/09

Keycap Visualizer

Key events are matched by physical key code, so the layout stays honest. Chords light up together. On touch, tap the keys.

  • Interaction
  • Keyboard
Type or tap a key
-last key
0presses

Installation

Add Keycaps to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-keycaps

Or by URL: https://asafefe.dev/r/lab-keycaps.json

Brings along

  • utils

Usage

example.tsx5 lines
import { Keycaps } from "@/components/lab/keycaps"

export function Example() {
  return <Keycaps onPress={(code, label) => console.log(code, label)} />
}

Props

PropTypeDefaultDescription
rowsKeycap[][]QWERTYRows of { code, label, wide? }, matched by KeyboardEvent.code.
onPress(code: string, label: string) => void-Called once per press, not on auto-repeat.
listenbooleantrueListen to the physical keyboard. Inputs are ignored.
keyClassNamestring-Classes for every key.