{"_id":"keymaster","_rev":"680210","name":"keymaster","description":"library for defining and dispatching keyboard shortcuts","dist-tags":{"latest":"1.6.2"},"maintainers":[{"name":"ded","email":""},{"name":"thomasfuchs","email":"thomas@fesch.at"}],"time":{"modified":"2021-08-30T02:33:40.000Z","created":"2011-08-31T21:49:45.665Z","1.6.2":"2014-05-16T12:33:57.880Z","1.0.2":"2011-09-08T05:49:02.496Z","1.0.1":"2011-08-31T21:55:27.844Z","1.0.0":"2011-08-31T21:49:45.665Z"},"users":{"thomasfuchs":true,"benji.":true,"princetoad":true,"stretchgz":true,"amongiants":true,"junjiansyu":true,"stev0thegreat":true,"hyteer":true,"juje":true,"yinfxs":true,"washingtonhua":true,"zagreos":true,"johniexu":true},"author":{"name":"Thomas Fuchs","email":"thomas@slash7.com","url":"http://mir.aculo.us"},"repository":{"type":"git","url":"https://github.com/madrobby/keymaster"},"versions":{"1.6.2":{"name":"keymaster","description":"library for defining and dispatching keyboard shortcuts","version":"1.6.2","author":{"name":"Thomas Fuchs","email":"thomas@slash7.com","url":"http://mir.aculo.us"},"repository":{"type":"git","url":"https://github.com/madrobby/keymaster"},"main":"./keymaster.js","bugs":{"url":"https://github.com/madrobby/keymaster/issues"},"homepage":"https://github.com/madrobby/keymaster","_id":"keymaster@1.6.2","dist":{"shasum":"e1ae54d0ea9488f9f60b66b668f02e9a1946c6eb","size":15446,"noattachment":false,"key":"/keymaster/-/keymaster-1.6.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/keymaster/download/keymaster-1.6.2.tgz"},"_from":".","_npmVersion":"1.3.17","_npmUser":{"name":"thomasfuchs","email":"thomas@fesch.at"},"maintainers":[{"name":"ded","email":""},{"name":"thomasfuchs","email":"thomas@fesch.at"}],"directories":{},"publish_time":1400243637880,"_cnpm_publish_time":1400243637880,"_hasShrinkwrap":false},"1.0.2":{"name":"keymaster","description":"library for defining and dispatching keyboard shortcuts","version":"1.0.2","author":{"name":"Thomas Fuchs"},"repository":{"type":"git","url":"git://github.com/madrobby/keymaster.git"},"main":"./keymaster.js","ender":"./ender.js","_npmJsonOpts":{"file":"/Users/dustindiaz/.npm/keymaster/1.0.2/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"keymaster@1.0.2","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.27","_nodeVersion":"v0.4.10","_defaultsLoaded":true,"dist":{"shasum":"3aaf143ec9ea7e47900317ad6b09bc2e57d21f83","size":13474,"noattachment":false,"key":"/keymaster/-/keymaster-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/keymaster/download/keymaster-1.0.2.tgz"},"maintainers":[{"name":"ded","email":""},{"name":"thomasfuchs","email":"thomas@fesch.at"}],"directories":{},"publish_time":1315460942496,"_cnpm_publish_time":1315460942496,"_hasShrinkwrap":false},"1.0.1":{"name":"keymaster","description":"library for defining and dispatching keyboard shortcuts","version":"1.0.1","author":{"name":"Thomas Fuchs"},"repository":{"type":"git","url":"git://github.com/madrobby/keymaster.git"},"main":"./keymaster.js","ender":"./ender.js","_npmJsonOpts":{"file":"/Users/dustindiaz/.npm/keymaster/1.0.1/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"keymaster@1.0.1","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.14","_nodeVersion":"v0.4.10","_defaultsLoaded":true,"dist":{"shasum":"3ef0474ce342ca6e3a240a25e8f1b3e5e521ca47","size":5614,"noattachment":false,"key":"/keymaster/-/keymaster-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/keymaster/download/keymaster-1.0.1.tgz"},"scripts":{},"maintainers":[{"name":"ded","email":""},{"name":"thomasfuchs","email":"thomas@fesch.at"}],"directories":{},"publish_time":1314827727844,"_cnpm_publish_time":1314827727844,"_hasShrinkwrap":false},"1.0.0":{"name":"keymaster","description":"library for defining and dispatching keyboard shortcuts","version":"1.0.0","author":{"name":"Thomas Fuchs"},"repository":{"type":"git","url":"git://github.com/madrobby/keymaster.git"},"main":"./keymaster.js","ender":"./ender.js","_npmJsonOpts":{"file":"/Users/dustindiaz/.npm/keymaster/1.0.0/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"keymaster@1.0.0","dependencies":{},"devDependencies":{},"engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.0.14","_nodeVersion":"v0.4.10","_defaultsLoaded":true,"dist":{"shasum":"3ef52ab4ca6df242729012b978b222a14251a4c4","size":5613,"noattachment":false,"key":"/keymaster/-/keymaster-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/keymaster/download/keymaster-1.0.0.tgz"},"scripts":{},"maintainers":[{"name":"ded","email":""},{"name":"thomasfuchs","email":"thomas@fesch.at"}],"directories":{},"publish_time":1314827385665,"_cnpm_publish_time":1314827385665,"_hasShrinkwrap":false}},"readme":"# keymaster.js\n\nKeymaster is a simple micro-library for defining and\ndispatching keyboard shortcuts in web applications.\n\nIt has no dependencies.\n\n*It’s a work in progress (e.g. beta), so spare me your nerdrage and instead\ncontribute! Patches are welcome, but they are not guaranteed to make\nit in.*\n\n## Usage\n\nInclude `keymaster.js` in your web app*, by loading it as usual:\n\n```html\n<script src=\"keymaster.js\"></script>\n```\n\nKeymaster has no dependencies and can be used completely standalone.\nIt should not interfere with any JavaScript libraries or frameworks.\n\n_*Preferably use a minified version that fits your workflow. You can\nrun `make` to have UglifyJS (if you have it installed) create a\n`keymaster.min.js` file for you._\n\n## Defining shortcuts\n\nOne global method is exposed, `key` which defines shortcuts when\ncalled directly.\n\n```javascript\n// define short of 'a'\nkey('a', function(){ alert('you pressed a!') });\n\n// returning false stops the event and prevents default browser events\nkey('ctrl+r', function(){ alert('stopped reload!'); return false });\n\n// multiple shortcuts that do the same thing\nkey('⌘+r, ctrl+r', function(){ });\n```\n\nThe handler method is called with two arguments set, the keydown `event` fired, and\nan object containing, among others, the following two properties:\n\n`shortcut`: a string that contains the shortcut used, e.g. `ctrl+r`\n`scope`: a string describing the scope (or `all`)\n\n```javascript\nkey('⌘+r, ctrl+r', function(event, handler){\n  console.log(handler.shortcut, handler.scope);\n});\n\n// \"ctrl+r\", \"all\"\n```\n\n\n## Supported keys\n\nKeymaster understands the following modifiers:\n`⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, and `⌘`.\n\nThe following special keys can be used for shortcuts:\n`backspace`, `tab`, `clear`, `enter`, `return`, `esc`, `escape`, `space`,\n`up`, `down`, `left`, `right`, `home`, `end`, `pageup`, `pagedown`, `del`, `delete`\nand `f1` through `f19`.\n\n\n## Modifier key queries\n\nAt any point in time (even in code other than key shortcut handlers),\nyou can query the `key` object for the state of any keys. This\nallows easy implementation of things like shift+click handlers. For example,\n`key.shift` is `true` if the shift key is currently pressed.\n\n```javascript\nif(key.shift) alert('shift is pressed, OMGZ!');\n```\n\n\n## Other key queries\n\nAt any point in time (even in code other than key shortcut handlers),\nyou can query the `key` object for the state of any key. This\nis very helpful for game development using a game loop. For example,\n`key.isPressed(77)` is `true` if the M key is currently pressed.\n\n```javascript\nif(key.isPressed(\"M\")) alert('M key is pressed, can ya believe it!?');\nif(key.isPressed(77)) alert('M key is pressed, can ya believe it!?');\n```\n\nYou can also get these as an array using...\n```javascript\nkey.getPressedKeyCodes() // returns an array of key codes currently pressed\n```\n\n\n## Scopes\n\nIf you want to reuse the same shortcut for separate areas in your single page app,\nKeymaster supports switching between scopes. Use the `key.setScope` method to set scope.\n\n```javascript\n// define shortcuts with a scope\nkey('o, enter', 'issues', function(){ /* do something */ });\nkey('o, enter', 'files', function(){ /* do something else */ });\n\n// set the scope (only 'all' and 'issues' shortcuts will be honored)\nkey.setScope('issues'); // default scope is 'all'\n```\n\n\n## Filter key presses\n\nBy default, when an `INPUT`, `SELECT` or `TEXTAREA` element is focused, Keymaster doesn't process any shortcuts.\n\nYou can change this by overwriting `key.filter` with a new function. This function is called before\nKeymaster processes shortcuts, with the keydown event as argument.\n\nIf your function returns false, then the no shortcuts will be processed.\n\nHere's the default implementation for reference:\n\n```javascript\nfunction filter(event){\n  var tagName = (event.target || event.srcElement).tagName;\n  return !(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');\n}\n```\n\nIf you only want _some_ shortcuts to work while in an input element, you can change the scope in the\n`key.filter` function. Here's an example implementation, setting the scope to either `'input'` or `'other'`.\nDon't forget to return `true` so the any shortcuts get processed.\n\n```javascript\nkey.filter = function(event){\n  var tagName = (event.target || event.srcElement).tagName;\n  key.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');\n  return true;\n}\n```\n\nHowever a more robust way to handle this is to use proper\nfocus and blur event handlers on your input element, and change scopes there as you see fit.\n\n\n## noConflict mode\n\nYou can call ```key.noConflict``` to remove the ```key``` function from global scope and restore whatever ```key``` was defined to before Keymaster was loaded. Calling ```key.noConflict``` will return the Keymaster ```key``` function.\n\n```javascript\nvar k = key.noConflict();\nk('a', function() { /* ... */ });\n\nkey()\n// --> TypeError: 'undefined' is not a function\n```\n\n\n## Unbinding shortcuts\n\nSimilar to defining shortcuts, they can be unbound using `key.unbind`.\n\n```javascript\n// unbind 'a' handler\nkey.unbind('a');\n\n// unbind a key only for a single scope\n// when no scope is specified it defaults to the current scope (key.getScope())\nkey.unbind('o, enter', 'issues');\nkey.unbind('o, enter', 'files');\n```\n\n\n## Notes\n\nKeymaster should work with any browser that fires `keyup` and `keydown` events,\nand is tested with IE (6+), Safari, Firefox and Chrome.\n\nSee [http://madrobby.github.com/keymaster/](http://madrobby.github.com/keymaster/) for a live demo.\n\n\n## CoffeeScript\n\nIf you're using CoffeeScript, configuring key shortcuts couldn't be simpler:\n\n```coffeescript\nkey 'a', -> alert('you pressed a!')\n\nkey '⌘+r, ctrl+r', ->\n  alert 'stopped reload!'\n  off\n\nkey 'o, enter', 'issues', ->\n  whatevs()\n\nalert 'shift is pressed, OMGZ!' if key.shift\n```\n\n\n## Contributing\n\nTo contribute, please fork Keymaster, add your patch and tests for it (in the `test/` folder) and\nsubmit a pull request.\n\n## TODOs\n\n* Finish test suite\n\nKeymaster is (c) 2011-2013 Thomas Fuchs and may be freely distributed under the MIT license.\nSee the `MIT-LICENSE` file.\n","_attachments":{},"homepage":"https://github.com/madrobby/keymaster","bugs":{"url":"https://github.com/madrobby/keymaster/issues"}}