High quality keybinding library
An object that gives the keyboard a first class identity, normalizes keyboard events across browsers, and allows binding to multiple keys.
This is a CommonJS version of the Brandon Benvie's Keyboard.
// create a new Keyboard object that is scoped to a specific DOM element or the windowvar kb = window;// when both ctrl+a are pressed togetherkbon'ctrl+a' 'activate' /***/ ;// when a, then be, then c are pressed in sequence and releasedkbon'a->b->c' 'release' /***/ ;// when any key is first pressed (including modifiers such as shift/control/etc.)kbon'*' 'activate' /***/// when any key is activated, pressed, repeats, releasedkbon'*'console.logeaction; // one of ['activate', 'repeat', 'release', 'press'];
view: a Window, Document, or Element which will be listened to
keyboard.on(keyCombo, [filter], callback)
keyCombo: a string that can be any key name or a combination of key names separated by '+' or '->'. The '+' combinator requires the keys be held together, '->' requires they be pressed in a specific sequence.
filter: optional and must be one
- activate: when a key is first depressed
- repeat: when a keydown due to the key being held down
- release: fires on keyup
- press: fires on keypress
callback: called with the keyboardEvent object if the keyCombo was a single key, or an array of keyboardEvent objects if the keyCombo was a combinator.
What type of action the event originated from. Same as the above filter types.
npm install keyboard-cjs --save
Usage as a Browserify's module:
var Keyboard = require'keyboard-cjs';var kb = window;
Usage as a RequireJS module:
require'Keyboard.js'var kb = window;;
This project "keyboard-cjs" was forked from the Brandon Benvie's project "Keyboard" on Feb 24, 2014 by Ilya Lakhin by the terms of MIT license, since the author has abandoned original project, and doesn't manage neither Issues, nor email requests.
The motivation of this fork was support of CommonJS interface for Browserify and RequireJS. But as far Brandon is away(I hope he is ok) I will maintain the project: fix bugs, implement new features by request etc. So please feel free to contribute in this project, or ask support in any form convenient for you.
When Brendon return back, I believe we will push all the changes made in the "keyboard-cjs" to the original project back.
- Issue tracker.
- My email and jabber: eliah.lakhin [at] gmail.com.
- My skype: "eliah.lakhin".