{"_id":"@andrewstart/keyboardjs","_rev":"1-013806c2fdc862c7aabd0a2d1987aa3b","name":"@andrewstart/keyboardjs","dist-tags":{"latest":"2.4.1"},"versions":{"2.4.1":{"name":"@andrewstart/keyboardjs","description":"A library for binding to keys and key combos without the pain of key codes and key combo conflicts.","version":"2.4.1","main":"index.js","scripts":{"test":"mocha test/**/*.spec.js","build":"browserify -g uglifyify -s keyboardJS ./index.js > ./dist/keyboard.min.js & browserify --debug -s keyboardJS ./index.js > ./dist/keyboard.js"},"keywords":["Key Binding, Keyboard, Key combos, Keyboard Shortcuts"],"author":{"name":"Robert Hurst","email":"robertwhurst@gmail.com"},"bugs":{"url":"https://github.com/RobertWHurst/KeyboardJS/issues"},"repository":{"type":"git","url":"git+ssh://git@github.com/RobertWHurst/KeyboardJS.git"},"license":"MIT","devDependencies":{"browserify":"^6.0.2","mocha":"^2.2.5","sinon":"^1.15.3","uglifyify":"^2.5.0"},"gitHead":"900d85a8cdb232a697f62db0f8961fbb9a249544","homepage":"https://github.com/RobertWHurst/KeyboardJS#readme","_id":"@andrewstart/keyboardjs@2.4.1","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"andrewstart","email":"start.andrew@gmail.com"},"dist":{"integrity":"sha512-QLVE9biNzWIZOergnn1zXpOAyBPqbDIGuH7vNl5dH4f4y+uLTbp42l57GGvb5KrAaLaYc94Spqg6h4/FlA0X5Q==","shasum":"373e649ae089aa69bccfbd774b03a4e9fd906e9a","tarball":"https://registry.npmjs.org/@andrewstart/keyboardjs/-/keyboardjs-2.4.1.tgz","fileCount":13,"unpackedSize":167229,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb1zRACRA9TVsSAnZWagAAGlIP/R+wAJhpdvWXCbiWgl/x\nasd+j1Q6NxwutRoNmOQmTuN7rB1F3aqDjcCtQu465ltaoMX4uxkr43wPUBbL\n2vPz0EYEOcKv70EYUDKcTBaTgUBSZrFXOBnlKIgi6Q1RIUdNoDj3NejY4NHc\nLY2qNrcfvGNoRMuwL0CFghe30+Rm44n656fVS0zJNpTl2GJ/zCQosRHRMcyA\ngtaIRfFHDhrfRCJJRL0V27t8r10Z7eMMWn8zIZ22vWEqX91+OcyzgUBACed1\nfZhsjCikwZ1xRRm7KJZcBtAlXlOjXC/ymhtshp+iji25ut/j9InyrPQTZo0I\nVHzWJVtXkkBaOxvgKkXg1u9a2L8W87lkdrq+fSeDSxT7cbBz3KpVtLBguWuZ\nfqjpkYPCwavhT5GI/4g51d8kqN6j/1EGG/LPRjVowT3PEUjw+9rThkKE1KLG\n4fnaDMI2+ccO+dPHWsxVqxRx4t/+qhiDQp7xq/SdfMMZ3oEKfwvLCeY9Uf/E\nVPx4/NEwBtrXL59Bej2MJSFgim1wYTh9J+UGILEeomEG9tqLMprDiyjTW/Yh\nNdQB9arkUmKPlkGNmUIE5+I4yBt1EE9DzAHdAX6Ue0OmhQ4G+YAHA/R93WNp\nraDc+1wWd+tGG0yUlSjgYYscM3QbwJjjQOSS5KFjxVps7eF0pg48WJqfZ4G/\nQ4tG\r\n=+D+q\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEa7b75wv+aCsMsRtsU0ez+dDrpRYpymYx4wil1N+65tAiA5Zg8EGXMy5jXTrbPV2AyZjwP+LwZM7sbl7MwrynM1jQ=="}]},"maintainers":[{"name":"andrewstart","email":"start.andrew@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/keyboardjs_2.4.1_1540830271871_0.14293809677234082"},"_hasShrinkwrap":false}},"time":{"created":"2018-10-29T16:24:31.718Z","2.4.1":"2018-10-29T16:24:32.046Z","modified":"2022-04-04T14:02:08.060Z"},"maintainers":[{"name":"andrewstart","email":"start.andrew@gmail.com"}],"description":"A library for binding to keys and key combos without the pain of key codes and key combo conflicts.","homepage":"https://github.com/RobertWHurst/KeyboardJS#readme","keywords":["Key Binding, Keyboard, Key combos, Keyboard Shortcuts"],"repository":{"type":"git","url":"git+ssh://git@github.com/RobertWHurst/KeyboardJS.git"},"author":{"name":"Robert Hurst","email":"robertwhurst@gmail.com"},"bugs":{"url":"https://github.com/RobertWHurst/KeyboardJS/issues"},"license":"MIT","readme":"\nKeyboardJS\n==========\n\n[ ![Build Status](https://travis-ci.org/RobertWHurst/KeyboardJS.svg?branch=master) ](https://travis-ci.org/RobertWHurst/KeyboardJS)\n[ ![NPM Version](http://img.shields.io/npm/v/keyboardjs.svg?style=flat) ](https://www.npmjs.org/package/keyboardjs)\n[ ![Downloads This Week](http://img.shields.io/npm/dm/keyboardjs.svg?style=flat) ](https://www.npmjs.org/package/keyboardjs)\n[ ![License](http://img.shields.io/npm/l/keyboardjs.svg?style=flat) ](https://www.npmjs.org/package/keyboardjs)\n\nKeyboardJS is a library for use in the browser (node.js compatible). It Allows\ndevelopers to easily setup key bindings. Use key combos to setup complex\nbindings. KeyboardJS also provides contexts. Contexts are great for single page\napplications. They allow you to scope your bindings to various parts of your\napplication. Out of the box keyboardJS uses a US keyboard locale. If you need\nsupport for a different type of keyboard KeyboardJS provides custom locale\nsupport so you can create with a locale that better matches your needs.\n\nKeyboardJS is available as a NPM module for use with\n[browserify](http://browserify.org/) (or in node.js). If you don't use\nbrowserify you can simply include\n[keyboard.js](https://github.com/RobertWHurst/KeyboardJS/blob/master/dist/keyboard.js)\nor\n[keyboard.min.js](https://github.com/RobertWHurst/KeyboardJS/blob/master/dist/keyboard.min.js)\nfrom the dist folder in this repo. These files are\n[UMD](https://github.com/umdjs/umd) wrapped so they can be used with or without\na module loader such as [requireJS](http://requirejs.org/).\n\n```shell\nnpm install keyboardjs\n```\n\nNote that all key names can be found in [./locales/us.js](https://github.com/RobertWHurst/KeyboardJS/blob/master/locales/us.js).\n\nIf you're looking for the previous v1.x.x release of KeyboardJS you can find it\n[here](https://github.com/RobertWHurst/KeyboardJS/tree/legacy).\n\n__Setting up bindings is easy__\n\n```javascript\nkeyboardJS.bind('a', function(e) {\n  console.log('a is pressed');\n});\nkeyboardJS.bind('a + b', function(e) {\n  console.log('a and b is pressed');\n});\nkeyboardJS.bind('a + b > c', function(e) {\n  console.log('a and b then c is pressed');\n});\nkeyboardJS.bind(['a + b > c', 'z + y > z'], function(e) {\n  console.log('a and b then c or z and y then z is pressed');\n});\nkeyboardJS.bind('', function(e) {\n  console.log('any key was pressed');\n});\n\n// keyboardJS.bind === keyboardJS.on === keyboardJS.addListener\n```\n\n\n__keydown vs a keyup__\n\n```javascript\nkeyboardJS.bind('a', function(e) {\n  console.log('a is pressed');\n}, function(e) {\n  console.log('a is released');\n});\nkeyboardJS.bind('a', null, function(e) {\n  console.log('a is released');\n});\n```\n\n\n__Prevent keydown repeat__\n\n```javascript\nkeyboardJS.bind('a', function(e) {\n  // this function will once run once even if a is held\n  e.preventRepeat();\n  console.log('a is pressed');\n});\n```\n\n\n__Unbind things__\n\n```javascript\nkeyboardJS.unbind('a', previouslyBoundHandler);\n// keyboardJS.unbind === keyboardJS.off === keyboardJS.removeListener\n```\n\n\n__Using contexts__\n\n```javascript\n\n  // these will execute in all contexts\n  keyboardJS.bind('a', function(e) {});\n  keyboardJS.bind('b', function(e) {});\n  keyboardJS.bind('c', function(e) {});\n\n  // these will execute in the index context\n  keyboardJS.setContext('index');\n  keyboardJS.bind('1', function(e) {});\n  keyboardJS.bind('2', function(e) {});\n  keyboardJS.bind('3', function(e) {});\n\n  // these will execute in the foo context\n  keyboardJS.setContext('foo');\n  keyboardJS.bind('x', function(e) {});\n  keyboardJS.bind('y', function(e) {});\n  keyboardJS.bind('z', function(e) {});\n\n  // if we have a router we can activate these contexts when appropriate\n  myRouter.on('GET /', function(e) {\n    keyboardJS.setContext('index');\n  });\n  myRouter.on('GET /foo', function(e) {\n    keyboardJS.setContext('foo');\n  });\n\n  // you can always figure out your context too\n  var contextName = keyboardJS.getContext();\n\n  // you can also set up handlers for a context without losing the current context\n  keyboardJS.withContext('bar', function() {\n    // these will execute in the bar context\n    keyboardJS.bind('7', function(e) {});\n    keyboardJS.bind('8', function(e) {});\n    keyboardJS.bind('9', function(e) {});\n  });\n```\n\n\n__pause, resume, and reset__\n\n```javascript\n\n// the keyboard will no longer trigger bindings\nkeyboardJS.pause();\n\n// the keyboard will once again trigger bindings\nkeyboardJS.resume();\n\n// all active bindings will released and unbound,\n// pressed keys will be cleared\nkeyboardJS.reset();\n```\n\n\n__pressKey, releaseKey, and releaseAllKeys__\n\n```javascript\n\n// pressKey\nkeyboardJS.pressKey('a');\n// or\nkeyboardJS.pressKey(65);\n\n// releaseKey\nkeyboardJS.releaseKey('a');\n// or\nkeyboardJS.releaseKey(65);\n\n// releaseAllKeys\nkeyboardJS.releaseAllKeys();\n```\n\n\n__watch and stop__\n\n```javascript\n// bind to the window and document in the current window\nkeyboardJS.watch();\n\n// or pass your own window and document\nkeyboardJS.watch(myDoc);\nkeyboardJS.watch(myWin, myDoc);\n\n// or scope to a specific element\nkeyboardJS.watch(myForm);\nkeyboardJS.watch(myWin, myForm);\n\n// detach KeyboardJS from the window and document/element\nkeyboardJS.stop();\n```\n","readmeFilename":"README.md"}