diff --git a/README.md b/README.md new file mode 100644 index 0000000..1cdb95d --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# hyperf-keybinds + +Quickly handle keyboard shortcuts and sequences in your app. + +## Install + +```bash +npm install hyperf-keybinds +``` + +## Quick Start + +```ts +import { createKeyHandler, KeybindEventTypes, ModifierKey } from 'hyperf-keybinds'; + +// Define a command +const commands = [ + { command: [{ key: 'KeyS', modifiers: [ModifierKey.Control] }], callback: () => console.log('Ctrl+S!') }, + { command: [{ key: 'KeyA', modifiers: []}, { key: 'KeyS', modifiers: []}], callback: () => console.log('a - s!')} +]; + +// Create handler and emitter +const { handler, emitter } = createKeyHandler(commands); + +// Attach to window +window.addEventListener('keydown', handler); + +// Listen to events +emitter.on(e => console.log(e.type)); +``` + +Now Ctrl+S triggers your callback and emits events. +Pressing a then s triggers a separate callback. diff --git a/package.json b/package.json index fcab762..a26898a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hyperf-keybinds", - "version": "0.1.0", + "version": "0.1.1", "description": "", "main": "dist/index.js",