keyboardjs2.5.1 • Public • Published
KeyboardJS is a library for use in the browser (node.js compatible). It Allows developers to easily setup key bindings. Use key combos to setup complex bindings. KeyboardJS also provides contexts. Contexts are great for single page applications. They allow you to scope your bindings to various parts of your application. Out of the box keyboardJS uses a US keyboard locale. If you need support for a different type of keyboard KeyboardJS provides custom locale support so you can create with a locale that better matches your needs.
KeyboardJS is available as a NPM module for use with browserify (or in node.js). If you don't use browserify you can simply include keyboard.js or keyboard.min.js from the dist folder in this repo. These files are UMD wrapped so they can be used with or without a module loader such as requireJS.
npm install keyboardjs
Note that all key names can be found in ./locales/us.js.
If you're looking for the previous v1.x.x release of KeyboardJS you can find it here.
Setting up bindings is easy
keyboardJS;keyboardJS;keyboardJS;keyboardJS;keyboardJS;// keyboardJS.bind === keyboardJS.on === keyboardJS.addListener
keydown vs a keyup
Prevent keydown repeat
keyboardJS;// keyboardJS.unbind === keyboardJS.off === keyboardJS.removeListener
// these will execute in all contextskeyboardJS;keyboardJS;keyboardJS;// these will execute in the index contextkeyboardJS;keyboardJS;keyboardJS;keyboardJS;// these will execute in the foo contextkeyboardJS;keyboardJS;keyboardJS;keyboardJS;// if we have a router we can activate these contexts when appropriatemyRouter;myRouter;// you can always figure out your context toovar contextName = keyboardJS;// you can also set up handlers for a context without losing the current contextkeyboardJS;
pause, resume, and reset
// the keyboard will no longer trigger bindingskeyboardJS;// the keyboard will once again trigger bindingskeyboardJS;// all active bindings will released and unbound,// pressed keys will be clearedkeyboardJS;
pressKey, releaseKey, and releaseAllKeys
// pressKeykeyboardJS;// orkeyboardJS;// releaseKeykeyboardJS;// orkeyboardJS;// releaseAllKeyskeyboardJS;
watch and stop
// bind to the window and document in the current windowkeyboardJS;// or pass your own window and documentkeyboardJS;keyboardJS;// or scope to a specific elementkeyboardJS;keyboardJS;// detach KeyboardJS from the window and document/elementkeyboardJS;
npm i keyboardjs