Press any key combination to see it detected below.
This demo reacts to real keydown/keyup events — best experienced with a physical keyboard.
—
A lightweight (~4.5KB gzip), dependency-free library for binding keyboard shortcuts — layout-agnostic, cross-platform, and safe by default.
Press any key combination to see it detected below.
This demo reacts to real keydown/keyup events — best experienced with a physical keyboard.
—
event.code — no need to
switch to a Latin layout
cmdOrCtrl — one binding, the right modifier on every
platform
g,g) — fires once every step
is pressed in order
A/D or ←/→ to move,
Space/W/↑ to jump, S/↓
to duck, Shift+D/→ (or
Shift+A/←) to dash — every one of these
is a real bindKeyboard.add() call, on a second instance
separate from the demo above.
Create a BindKeyboard instance when your component mounts
(useEffect in React, onMounted in Vue,
onMount in Svelte) and call
bindKeyboard.destroy() on unmount to remove its
listeners. The "Try it in your code" section above has a
copy-pasteable example for each framework, in both TypeScript and
JavaScript.
Yes. Setting keyMode: "code" matches by the physical key
position (event.code) instead of the character it
produces (event.key), so a binding for the key printed
"A" fires regardless of the active keyboard layout.
Use the cmdOrCtrl modifier alias, e.g.
bindKeyboard.add("cmdOrCtrl+k", callback) — it resolves
to metaKey on Mac and ctrlKey
everywhere else, so one binding covers both platforms.
Yes. Constructing a BindKeyboard instance is safe during
SSR: with the default autostart: true, it skips attaching
listeners instead of throwing when there's no DOM yet.
Not unless you opt in. Setting
checkInputElements: true on the constructor suppresses
bindings while a text field, textarea, select, or contenteditable
element is focused, with a per-binding
allowInInputElements: true override for shortcuts like
Escape that should still fire.
About 4.5KB gzipped, with zero runtime dependencies.