{"_id":"@buildwithdarsh/keyboardjs","name":"@buildwithdarsh/keyboardjs","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@buildwithdarsh/keyboardjs","version":"1.0.0","description":"A tiny, modular keyboard input library — hotkeys, sequences, chords, scopes, layouts, recorder","main":"dist/keyboard.umd.js","module":"dist/keyboard.esm.js","types":"dist/keyboard.d.ts","exports":{".":{"types":"./dist/keyboard.d.ts","import":"./dist/keyboard.esm.js","require":"./dist/keyboard.umd.js"}},"publishConfig":{"access":"public"},"scripts":{"build":"rollup -c && rm -rf example/dist && cp -r dist example/dist","typecheck":"tsc --noEmit","dev":"rollup -c -w"},"keywords":["keyboard","hotkeys","shortcuts","keybindings","sequences","chords","layouts"],"author":{"name":"Darsh Gupta"},"license":"MIT","type":"module","devDependencies":{"@rollup/plugin-terser":"^1.0.0","@rollup/plugin-typescript":"^12.1.2","rollup":"^4.34.8","rollup-plugin-dts":"^6.1.1","tslib":"^2.8.1","typescript":"^5.7.3"},"_id":"@buildwithdarsh/keyboardjs@1.0.0","gitHead":"070ceb8c43b55e17581f44d0ab747c401ecd0fe1","_nodeVersion":"22.20.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-mheIT/PvO+POsuTBE5zFOF80Zpo3dqakcMsyKj+1XoMlVDZ7VXlulBBFHT4P+1Hi16p1LlT3q9LAYdteGZIOaQ==","shasum":"081514f5a4babe3e8786aec3725ad8a6666dee30","tarball":"https://registry.npmjs.org/@buildwithdarsh/keyboardjs/-/keyboardjs-1.0.0.tgz","fileCount":7,"unpackedSize":107166,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDltMARzvJc3MDdszjdCu6xDED/lIGO/rfR1q8xfdn2DgIhALVOFDTNxWqxa+r/QvEnfVrVvkr3YtSxCsAR6CpO2l80"}]},"_npmUser":{"name":"withdarsh","email":"withdarsh@gmail.com"},"directories":{},"maintainers":[{"name":"withdarsh","email":"withdarsh@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/keyboardjs_1.0.0_1779077161083_0.857776228865458"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-18T04:06:00.996Z","1.0.0":"2026-05-18T04:06:01.236Z","modified":"2026-05-18T04:06:01.516Z"},"maintainers":[{"name":"withdarsh","email":"withdarsh@gmail.com"}],"description":"A tiny, modular keyboard input library — hotkeys, sequences, chords, scopes, layouts, recorder","keywords":["keyboard","hotkeys","shortcuts","keybindings","sequences","chords","layouts"],"author":{"name":"Darsh Gupta"},"license":"MIT","readme":"> This project is made with the help of Claude (1M context).\n\n<div align=\"center\">\n\n<br />\n\n<img src=\"https://img.shields.io/badge/keyboardjs-v1.0.0-30d158?style=for-the-badge&labelColor=000000\" alt=\"version\" />\n<img src=\"https://img.shields.io/badge/gzip-~4KB-ff9f0a?style=for-the-badge&labelColor=000000\" alt=\"gzip\" />\n<img src=\"https://img.shields.io/badge/dependencies-0-bf5af2?style=for-the-badge&labelColor=000000\" alt=\"deps\" />\n<img src=\"https://img.shields.io/badge/license-MIT-ff375f?style=for-the-badge&labelColor=000000\" alt=\"license\" />\n\n<br /><br />\n\n# KeyBoardJS\n\n**The tiny keyboard library.**\n\nHotkeys, sequences, chords, scopes, layouts, and a recorder — all in one script tag. Zero dependencies, TypeScript first.\n\n</div>\n\n---\n\n## Why KeyBoardJS?\n\n| | hotkeys-js | Mousetrap | **KeyBoardJS** |\n|---|---|---|---|\n| Hotkeys | Yes | Yes | **Yes** |\n| Key sequences (`g g`) | No | Yes | **Yes** |\n| Chords (hold `j+k`) | No | No | **Yes** |\n| Named scopes | Partial | No | **Yes** (stackable) |\n| Layout remap (Dvorak/Colemak) | No | No | **Yes** |\n| Record + replay | No | No | **Yes** |\n| TypeScript-first | No | No | **Yes** |\n| Gzip size | ~3KB | ~3KB | **~4KB (everything)** |\n\n---\n\n## Quick Start\n\n```html\n<script src=\"https://keyboardjs.work.withdarsh.com/dist/keyboard.umd.js\"></script>\n<script>\n  Keyboard.init();\n\n  Keyboard.on('ctrl+k', () => openPalette());\n  Keyboard.on(['g', 'g'], () => window.scrollTo(0, 0));\n  Keyboard.chord(['j', 'k'], () => exitInsertMode());\n</script>\n```\n\nOr with a bundler:\n\n```ts\nimport Kb from 'KeyBoardJS';\n\nKb.init();\nKb.on('shift+?', () => showHelp());\n```\n\n---\n\n## API\n\n### `Kb.init(opts?)`\nAttach listeners to `window` (or a custom `EventTarget`).\n\n### `Kb.on(combo, handler, opts?)`\nRegister a hotkey. Accepts `'ctrl+k'` style strings.\n\n```js\nKb.on('ctrl+shift+p', (e) => { ... }, {\n  scope: 'editor',      // only fire in this scope\n  allowInInput: false,  // ignore when typing in inputs\n  preventDefault: true, // stop default browser behaviour\n});\n```\n\n### `Kb.on([k1, k2, ...], handler, opts?)`\nRegister a **sequence**. Fires when keys are pressed in order within `timeout` ms.\n\n```js\nKb.on(['g', 'g'], gotoTop, { timeout: 800 });\n```\n\n### `Kb.chord([k1, k2, ...], handler, opts?)`\nRegister a **chord** — keys pressed simultaneously within `window` ms.\n\n```js\nKb.chord(['j', 'k'], exitInsertMode, { window: 200 });\n```\n\n### Scopes\n\n```js\nKb.scope('editor');          // activate\nKb.scope();                  // read current\nconst pop = Kb.pushScope('modal');\npop();                       // restore previous\n```\n\nBindings with `scope: 'global'` always fire. Others only fire in the active scope.\n\n### Layouts\n\n```js\nKb.layout('dvorak'); // or 'colemak' | 'qwerty'\n```\n\n### Recorder\n\n```js\nKb.record();\n// ... user types ...\nconst frames = Kb.stop();\nawait Kb.replay(frames, 2); // 2x speed\n```\n\n### Misc\n\n```js\nKb.off('ctrl+k');    // remove\nKb.clear();          // remove all\nKb.list();           // [{ combo, scope }, ...] — good for help dialogs\nKb.format('ctrl+k'); // \"Ctrl + K\"\n```\n\n---\n\n## Platform support (Mac / Windows / Linux)\n\nUse `mod` (a.k.a. `cmdOrCtrl`) for bindings that should work the same on every OS:\n\n```js\nKb.on('mod+k', openPalette);   // ⌘K on Mac, Ctrl+K on Windows/Linux\nKb.on('mod+shift+p', command); // ⇧⌘P / Ctrl+Shift+P\n```\n\nInspect the detected platform:\n\n```js\nKb.platform   // 'mac' | 'windows' | 'linux' | 'other'\nKb.isMac      // true on macOS / iPadOS / iOS\nKb.modKey     // 'meta' (Mac) or 'control' (PC)\nKb.format('mod+shift+k')  // \"⇧⌘K\" on Mac, \"Ctrl + Shift + K\" on PC\n```\n\n`Kb.format()` returns Mac glyphs (`⌘ ⌥ ⇧ ⌃ ↵ ⌫ ⇥`) on Apple platforms and word labels (`Ctrl + Shift + K`) elsewhere — drop straight into tooltips and help dialogs.\n\n## Key names\n\nCase-insensitive. Aliases supported:\n\n- `mod` / `cmdOrCtrl` / `commandOrControl` — **platform-aware** (Cmd on Mac, Ctrl elsewhere)\n- `ctrl` / `control`\n- `cmd` / `meta` / `command` / `win`\n- `alt` / `option` / `opt`\n- `esc` / `escape`\n- `return` / `enter`\n- `space` / `spacebar`\n- `up` / `down` / `left` / `right` (arrow keys)\n- `pgup` / `pgdn`, `del`, `ins`\n\n---\n\n## License\n\nMIT © Darsh Gupta\n","readmeFilename":"README.md","_rev":"1-6c96922a91063c85fdb0cfbc589869d2"}