Skip to content

XKeyboard — Keyboard Diagram ​

A pure-SVG keyboard diagram component, zero third-party dependencies. Ships with 5 layout presets and supports key annotation lines, zone labels, and hover/click linked highlighting — ideal for product docs, shortcut references, and operation guides.

Live Demo ​

功能键主键盘编辑键方向键数字键盘EscF1F2F3F4F5F6F7F8F9F10F11F12`1234567890-=BkspTabQWERTYUIOP[]\CapsASDFGHJKL;'EnterShiftZXCVBNM,./ShiftCtrlWinAltSpaceAltWinMenuCtrlInsHomePgUpDelEndPgDn↑←↓→NumLk÷×−789+456123Enter0.Start menuExit/BackStart menuSpacebar
vue
<XKeyboard
  type="full"
  :keys="{ Esc: 'Exit/Back', Win: 'Start menu', Space: 'Spacebar' }"
  :show-group-label="true"
/>

Props ​

PropTypeDefaultDescription
typestring'full'Layout preset (see table below)
keysRecord<string, string>{}Key annotations { keyName: text }; key names must match the layout
widthnumber920Max width (px); scales down proportionally when the container is narrower
heightnumber0Height (px); 0 means auto-adapt to the viewBox ratio
keyColorstring''Keycap fill color; empty falls back to --surface
keyTextColorstring''Keycap text color; empty falls back to --text-1
accentColorstring''Accent color; empty falls back to --brand-1
lineColorstring''Annotation line color; empty falls back to --brand-1
labelColorstring''Annotation text color; empty falls back to --text-2
showKeyLabelbooleantrueWhether to draw keycap text
showGroupLabelbooleanfalseWhether to show zone labels
annotationsbooleantrueWhether to draw annotation lines and labels
highlightKeysstring[][]Array of key names to highlight

Events ​

EventCallback argumentDescription
select(name: string)Fired when any key is clicked, returning that key's name

Layout Presets ​

typeCompositionCanvas ratio
alphaThree alpha rows (QWERTY / ASDF / ZXCV)Wide & flat
numericNumpad (NumLk / arithmetic / double-height + Enter)Near square
fullFunction row + main keyboard + edit keys + arrow keys + numpadWide & flat
laptopFunction row + main keyboard (Menu replaced by Fn) + arrow keysWide & flat
laptopTouchSame as laptop, with a touchpad drawn below the keyboardSlightly taller

Usage Notes ​

  • Color props fall back to theme CSS variables when left empty; dark mode needs no extra configuration.
  • Annotation keys are grouped to an edge based on their position relative to the keyboard center; labels on the same edge spread along the edge to avoid overlap.
  • Key names must match the layout exactly to take effect (e.g. Bksp not Backspace, ↑ not Up).
  • Pure SVG, scales without distortion, no ResizeObserver needed.

基于 VitePress + Vue 3 构建