Components

Key Screen

A floating overlay that captures and displays keyboard shortcuts and keypresses in real time — ideal for demos, screencasts, and presentations.

press any key

Features

  • Listens to keydown / keyup events globally and renders the active key combo as styled keycaps.
  • Modifier keys (Ctrl, , Alt, Shift) are captured and ordered consistently before regular keys.
  • Special keys are normalized to readable symbols — Space, , , , , , , Esc, and more.
  • Combo history shows the last N presses, fading older entries and removing the current one after a configurable delay.
  • Five anchor positions: bottom-left, bottom-right, bottom-center, top-left, top-right.
  • Keycap styling uses shadcn/ui CSS variables — inherits your theme automatically.
  • pointer-events: none so it never interferes with the page below it.

Installation

pnpm dlx shadcn@latest add https://www.harshalvk.com/r/key-screen.json

Usage

import { KeyScreen } from '@/components/key-screen';
<KeyScreen position="bottom-left" fadeDelay={1800} historySize={3} />

API Reference

KeyScreen

PropTypeDefaultDescription
positionbottom-left bottom-right bottom-center top-left top-right"bottom-left"Anchor corner for the floating overlay.
fadeDelaynumber1800Milliseconds before the current combo fades out after the last keypress.
historySizenumber3Maximum number of combos shown simultaneously. Older entries scroll off.
verbosebooleanfalseShow full modifier names (Control, Meta) instead of symbols (Ctrl, ).
classNamestringAdditional classes applied to the outermost container.

Notes

  • The component attaches listeners directly to window, so it captures keypresses regardless of which element has focus. Wrap it in a context or conditionally render it to scope it to a specific mode (e.g. a "presentation" toggle).
  • A blur event on window clears the tracked pressed-key set, preventing stuck modifier keys when the user tabs away.
  • Modifier-only presses (Shift held alone, etc.) do not emit a combo — a regular key must be included.
  • The keycap depth effect is achieved with an inset box-shadow using --border variables; it follows your shadcn/ui theme without any extra configuration.
  • For screencasts or live demos, pair with a useHotkeys hook from react-hotkeys-hook to trigger side-effects on specific shortcuts while KeyScreen handles the visual feedback independently.