CanadaRobertWHurst/KeyboardJS
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.
🎹 KeyboardJS: Pain-Free Keyboard Binding in JavaScript
Bind keyboard shortcuts without memorizing key codes or fighting combo conflicts.
KeyboardJS by Robert Hurst is a JavaScript library for browser and node.js that lets developers bind keyboard actions without dealing with messy key codes. It handles simple keys, combinations, sequences, and modifier keys like alt, shift, and ctrl. With US locale default, custom locale support, and context system for single-page applications, it's a practical tool for web key handling. Note: the author recommends checking out their newer library Keystrokes for new projects.
✨ Highlights
- Key combos without key codes: bind using readable strings like 'a + b' or 'alt + shift > c'
- Contexts for SPAs: scope bindings to specific application views
- Custom locale support: create keyboard layouts beyond US default
- Press/release distinction: separate handlers for keydown and keyup, or use bindPress/bindRelease
- Prevent keydown repeat: e.preventRepeat() stops repeated calls when holding a key
- Pause, resume, reset: control binding state, clear everything with reset()
- Programmatic key simulation: pressKey, releaseKey, releaseAllKeys for testing
- TypeScript ready: ships with its own types, no @types needed
💡 Why it matters
KeyboardJS solves the common frustration of working with raw keyboard events in JavaScript. Instead of managing numeric key codes and handling combo conflicts manually, developers can use human-readable strings. The context system is particularly useful for SPAs where different views need different shortcuts. While the author now points to Keystrokes as a more refined alternative, KeyboardJS remains a solid, well-documented option with a proven track record (2k+ stars) and features like sequence binding ('a + b > c') that are rare in similar libraries.
#JavaScript #KeyboardEvents #WebDevelopment #OpenSource #TiniX
Similar Projects
Discover other similar projects and AI models.
Keystrokes as an easy to use library for binding functions to keys and key combos. It can be used with any TypeScript or JavaScript project, even in non-browser environments.
📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
Reverse engineer anything with agents, from app behavior down to native binaries.
freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core