KeyBoard.js DOM virtual keyboard library

Render Korean standard (KR/EN), US ANSI, Japanese JIS, and Chinese Zhuyin or Pinyin keyboards in any DOM container, with programmatic key marking, press locking, tooltips, and physical code events.

  • 0 dependencies
  • Single file keyboard.js
  • 5 layouts (KR default)
  • ResizeObserver auto-fit

Interactive simulator

Test auto and manual typing modes, CJK layouts, key marking, tooltips, and physical key code logs against one live instance.

Last key - -
API const kb = new KeyBoard('#keyboard-area', { layout: 'en', syncPhysicalKeyboard: true });

US ANSI English layout loaded. Click virtual keys or type on your keyboard.

Supports English, Hangul, Kana, Zhuyin, and physical DOM codes

Mark presets and selective clearing

Selective clear (clearMarks)

Responsive scaling lab

ResizeObserver and sub-pixel unit widths (u × keySize + (u - 1) × gap) keep all rows flush across mobile, tower, and wide-banner frames.

720px
280px
Container box
720 × 280
Aspect ratio
2.57:1
Computed key size
-
Applied scale
1.000×
Rows / cluster
6 rows · right

Multi-panel aspect and layout matrix

Six independent KeyBoard instances across KR, JP, ZH, CN, and EN layouts rendered simultaneously.

Wide banner · Korean (ko) -
Standard dark · Japanese JIS (ja) -
Square panel · Chinese Zhuyin (zh) -
60% compact · Chinese Pinyin (zh-cn) -
Tall tower · English Mono (en) -
Micro thumbnail · Korean (ko) -

API reference

Drop in a single script file with zero external packages or build configuration.

Quick start (HTML)
<div id="keyboard"></div>
<script src="keyboard.js"></script>
<script>
  // Default layout: 'ko' (Korean KS X 5002 KR/EN)
  const kb = new KeyBoard('#keyboard', {
    layout: 'ko',          // 'ko' | 'en' | 'ja' | 'zh' | 'zh-cn'
    theme: 'light',
    syncPhysicalKeyboard: true
  });

  kb.mark(['w', 'a', 's', 'd'], '#1a4be0');
  kb.onpress((key, el, detail) => {
    console.log(detail.code, detail.sub, detail.source);
  });
</script>
Constructor options Defaults
{
  layout: 'ko',               // 'ko' | 'en' | 'ja' | 'zh' | 'zh-cn'
  hiddenEscape: false,        // Hide Escape key
  hiddenFunction: false,      // Hide F1-F12 row
  hiddenArrow: false,         // Hide arrow cluster
  arrowPosition: 'right',     // 'right' | 'bottom'
  theme: 'light',             // 'light' | 'dark' | 'mono'
  syncPhysicalKeyboard: false,// Mirror hardware keystrokes
  injectStyles: true,         // Auto-inject base stylesheet
  debug: false                // Log layout metrics to console
}
mark(keys, colorOrOpts)

Highlight keys with a color string or options object and automatic WCAG text contrast.

clearMarks(keys?)

Remove custom marks from selected keys or the entire keyboard.

click(keys, opts?)

Actuate keys momentarily for a specified pressDelay duration.

press / unpress(keys, opts?)

Programmatically hold keys down or release locked key states.

flow(keys, opts?)

Animate sequential key actuation from an array or string; cancel with stopFlow().

hide / show(keys)

Hide or reveal individual keys while preserving exact row alignment.

tooltip(keys, opts, html)

Attach hover, click, or press tooltips in relative or centered positions.

onpress / onunpress

Register global or per-key/code listeners with an unsubscribe return function.

setLayout(layout)

Switch between ko, en, ja, zh, and zh-cn keyboard layouts live.

updateOptions(opts)

Update layout, arrow placement, or hidden rows without losing event listeners.

reset(keys?) / destroy()

Restore default key states or detach DOM nodes, observers, and open tooltips.

Frequently asked questions

Technical answers on integration, multilingual layouts, and responsive behavior.

Does KeyBoard.js require dependencies or a build step?

No. keyboard.js ships as a standalone vanilla JavaScript file that works via a plain script tag or CommonJS import.

Which keyboard layouts are built in?

Five layouts are included: Korean KS X 5002 KR/EN (ko, default), US ANSI English (en), Japanese JIS Kana (ja), Chinese Zhuyin (zh), and Simplified Chinese Pinyin (zh-cn).

Can it distinguish Left and Right Shift or Ctrl keys?

Yes. Key state is stored per physical DOM code such as ControlLeft and ControlRight, so left and right modifiers can be styled and logged separately.

Does it fit narrow mobile screens without horizontal overflow?

ResizeObserver recalculates key unit sizes and scale automatically whenever the container resizes, keeping all six rows intact down to 320px viewports.