{"name":"hotkeys-js","version":"1.0.6","description":"A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.","main":"dist/hotkeys.js","keywords":["hotkey","hotkeys","hotkeys-js","hotkeysjs","key","keys","keyboard","shortcuts"],"repository":{"type":"git","url":"git+https://github.com/jaywcjlove/hotkeys.git"},"devDependencies":{"bannerjs":"^1.0.4","gulp":"^3.9.0","gulp-banner":"^0.1.3","gulp-rename":"^1.2.2","gulp-sourcemap":"^1.0.1","gulp-uglify":"^1.5.1","gulp-umd":"^0.2.0","gulp-util":"^3.0.7","gulp-watch":"^4.3.5"},"gitHead":"6251abbefb9befc1763e5df9aeae526b8dba0e37","bugs":{"url":"https://github.com/jaywcjlove/hotkeys/issues"},"homepage":"https://github.com/jaywcjlove/hotkeys#readme","_id":"hotkeys-js@1.0.6","scripts":{},"_shasum":"72522e9fa41ad17ce02b9c33d891891e59a009f9","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"jslite","email":"398188662@qq.com"},"dist":{"shasum":"72522e9fa41ad17ce02b9c33d891891e59a009f9","tarball":"http://registry-npm.ywwl.com/hotkeys-js/download/hotkeys-js-1.0.6.tgz","integrity":"sha512-gXIm2tJe/q6z3NLHqB4HNKGxZCOnnGCWtJiMBSopTZs/XuoYeiGa225ATVZH/YwRri8eFYCp/DRhK9S8GRUCng==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGqIO/KugA3LoI8grvXllx0HzEkBrNpGodlMS2iEoSDrAiBzaAeW6CW48AJNH38BU37WVCfofB7Rn89ok4OlSRM9CA=="}],"size":11110,"noattachment":false,"key":"/hotkeys-js/-/hotkeys-js-1.0.6.tgz"},"maintainers":[{"name":"jslite","email":"398188662@qq.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/hotkeys-js-1.0.6.tgz_1478971126538_0.5342835721094161"},"directories":{},"readme":"# Hotkeys\n\n<!--dividing-->\n\n[![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor)\n[![](https://img.shields.io/npm/dm/hotkeys-js?logo=npm)](https://www.npmjs.com/package/hotkeys-js)\n[![](https://img.shields.io/github/stars/jaywcjlove/hotkeys-js.svg)](https://github.com/jaywcjlove/hotkeys/stargazers)\n![no dependencies](http://jaywcjlove.github.io/sb/status/no-dependencies.svg)\n[![GitHub Actions CI](https://github.com/jaywcjlove/hotkeys-js/actions/workflows/ci.yml/badge.svg)](https://github.com/jaywcjlove/hotkeys-js/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/jaywcjlove/hotkeys/badge.svg?branch=master)](https://coveralls.io/github/jaywcjlove/hotkeys?branch=master)\n[![jaywcjlove/hotkeys-js](https://jaywcjlove.github.io/sb/lang/chinese.svg)](https://github.com/jaywcjlove/hotkeys-js/blob/master/README-zh.md)\n[![jaywcjlove/hotkeys-js](https://jaywcjlove.github.io/sb/ico/gitee.svg)](https://gitee.com/jaywcjlove/hotkeys)\n\nHotKeys.js is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint ([~6kB](https://bundlephobia.com/result?p=hotkeys-js)) (gzipped: **`2.8kB`**), and has no dependencies. It should not interfere with any JavaScript libraries or frameworks. Official document [demo preview](https://jaywcjlove.github.io/hotkeys-js). [More examples](https://github.com/jaywcjlove/hotkeys-js/issues?q=label%3ADemo+).\n\n```bash\n╭┈┈╮          ╭┈┈╮  ╭┈┈╮\n┆  ├┈┈..┈┈┈┈┈.┆  └┈╮┆  ├┈┈..┈┈┈┈┈..┈┈.┈┈..┈┈┈┈┈.\n┆     ┆┆  □  ┆┆   ┈┤┆    < ┆  -__┘┆  ┆  ┆┆__ ┈┈┤\n╰┈┈┴┈┈╯╰┈┈┈┈┈╯╰┈┈┈┈╯╰┈┈┴┈┈╯╰┈┈┈┈┈╯╰┈┈┈  ┆╰┈┈┈┈┈╯\n                                  ╰┈┈┈┈┈╯\n```\n\n## Usage\n\nYou will need `Node.js` installed on your system.\n\n```bash\nnpm install hotkeys-js --save\n```\n\n```js\nimport hotkeys from 'hotkeys-js';\n\nhotkeys('f5', function(event, handler){\n  // Prevent the default refresh event under WINDOWS system\n  event.preventDefault()\n  alert('you pressed F5!')\n});\n```\n\nOr manually download and link **hotkeys.js** in your HTML, It can also be downloaded via [UNPKG](https://unpkg.com/hotkeys-js/dist/):\n\nCDN: [UNPKG](https://unpkg.com/hotkeys-js/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/hotkeys-js@3.7.3/) | [Githack](https://raw.githack.com/jaywcjlove/hotkeys/master/dist/hotkeys.min.js) | [Statically](https://cdn.statically.io/gh/jaywcjlove/hotkeys/master/dist/hotkeys.min.js) | [bundle.run](https://bundle.run/hotkeys-js@3.7.3)\n\n```html\n<script src=\"https://unpkg.com/hotkeys-js/dist/hotkeys.min.js\"></script>\n<script type=\"text/javascript\">\nhotkeys('ctrl+a,ctrl+b,r,f', function (event, handler){\n  switch (handler.key) {\n    case 'ctrl+a': alert('you pressed ctrl+a!');\n      break;\n    case 'ctrl+b': alert('you pressed ctrl+b!');\n      break;\n    case 'r': alert('you pressed r!');\n      break;\n    case 'f': alert('you pressed f!');\n      break;\n    default: alert(event);\n  }\n});\n</script>\n```\n\n### Used in React\n\n[react-hotkeys](https://github.com/jaywcjlove/react-hotkeys) is the React component that listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts. Detailed use method please see its documentation [react-hotkeys](https://github.com/jaywcjlove/react-hotkeys).\n\n[react-hotkeys-hook](https://github.com/JohannesKlauss/react-hotkeys-hook) - React hook for using keyboard shortcuts in components. Make sure that you have at least version 16.8 of react and react-dom installed, or otherwise hooks won't work for you.\n\n## Browser Support\n\nHotkeys.js has been tested and should work in.\n\n```shell\nInternet Explorer 6+\nSafari\nFirefox\nChrome\n```\n\n## Supported Keys\n\nHotKeys understands the following modifiers: `⇧`, `shift`, `option`, `⌥`, `alt`, `ctrl`, `control`, `command`, and `⌘`.\n\nThe following special keys can be used for shortcuts: backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete, f1 through f19, num_0 through num_9, num_multiply, num_add, num_enter, num_subtract, num_decimal, num_divide.\n\n`⌘` Command()\n`⌃` Control\n`⌥` Option(alt)\n`⇧` Shift\n`⇪` Caps Lock(Capital)\n~~`fn` Does not support fn~~\n`↩︎` return/Enter space\n\n## Defining Shortcuts\n\nOne global method is exposed, key which defines shortcuts when called directly.\n\n```js\nhotkeys([keys:<String>], [option:[string|object|function]], [callback:<function>])\n```\n\n\n```js\nhotkeys('f5', function(event, handler) {\n  // Prevent the default refresh event under WINDOWS system\n  event.preventDefault();\n  alert('you pressed F5!');\n});\n\n// Returning false stops the event and prevents default browser events\n// Mac OS system defines `command + r` as a refresh shortcut\nhotkeys('ctrl+r, command+r', function() {\n  alert('stopped reload!');\n  return false;\n});\n\n// Single key\nhotkeys('a', function(event,handler){\n  //event.srcElement: input\n  //event.target: input\n  if(event.target === \"input\"){\n      alert('you pressed a!')\n  }\n  alert('you pressed a!')\n});\n\n// Key Combination\nhotkeys('ctrl+a,ctrl+b,r,f', function (event, handler){\n  switch (handler.key) {\n    case 'ctrl+a': alert('you pressed ctrl+a!');\n      break;\n    case 'ctrl+b': alert('you pressed ctrl+b!');\n      break;\n    case 'r': alert('you pressed r!');\n      break;\n    case 'f': alert('you pressed f!');\n      break;\n    default: alert(event);\n  }\n});\n\nhotkeys('ctrl+a+s', function() {\n    alert('you pressed ctrl+a+s!');\n});\n\n// Using a scope\nhotkeys('*','wcj', function(event){\n  console.log('do something', event);\n});\n```\n\n#### option\n\n- `scope<String>`\n- `element<HTMLElement>`\n- `keyup<Boolean>`\n- `keydown<Boolean>`\n- `splitKey<string>` (default is `+`)\n- `capture<Boolean>`\n- `single<Boolean>`\n\n```js\nhotkeys('o, enter', {\n  scope: 'wcj',\n  element: document.getElementById('wrapper'),\n}, function() {\n  console.log('do something else');\n});\n\nhotkeys('ctrl-+', { splitKey: '-' }, function(e) {\n  console.log('you pressed ctrl and +');\n});\n\nhotkeys('+', { splitKey: '-' }, function(e){\n  console.log('you pressed +');\n})\n```\n\n**keyup**\n\n**key down** and **key up** both perform callback events.\n\n```js\nhotkeys('ctrl+a,alt+a+s', {keyup: true}, function(event, handler) {\n  if (event.type === 'keydown') {\n    console.log('keydown:', event.type, handler, handler.key);\n  }\n\n  if (event.type === 'keyup') {\n    console.log('keyup:', event.type, handler, handler.key);\n  }\n});\n```\n\n## API REFERENCE\n\nAsterisk \"*\"\n\nModifier key judgments\n\n```js\nhotkeys('*', function() {\n  if (hotkeys.shift) {\n    console.log('shift is pressed!');\n  }\n\n  if (hotkeys.ctrl) {\n    console.log('ctrl is pressed!');\n  }\n\n  if (hotkeys.alt) {\n    console.log('alt is pressed!');\n  }\n\n  if (hotkeys.option) {\n    console.log('option is pressed!');\n  }\n\n  if (hotkeys.control) {\n    console.log('control is pressed!');\n  }\n\n  if (hotkeys.cmd) {\n    console.log('cmd is pressed!');\n  }\n\n  if (hotkeys.command) {\n    console.log('command is pressed!');\n  }\n});\n```\n\n### setScope\n\nUse the `hotkeys.setScope` method to set scope. There can only be one active scope besides 'all'.  By default 'all' is always active.\n\n```js\n// Define shortcuts with a scope\nhotkeys('ctrl+o, ctrl+alt+enter', 'issues', function() {\n  console.log('do something');\n});\nhotkeys('o, enter', 'files', function() {\n  console.log('do something else');\n});\n\n// Set the scope (only 'all' and 'issues' shortcuts will be honored)\nhotkeys.setScope('issues'); // default scope is 'all'\n```\n\n### getScope\n\nUse the `hotkeys.getScope` method to get scope.\n\n```js\nhotkeys.getScope();\n```\n\n### deleteScope\n\nUse the `hotkeys.deleteScope` method to delete a scope. This will also remove all associated hotkeys with it.\n\n```js\nhotkeys.deleteScope('issues');\n```\nYou can use second argument, if need set new scope after deleting.\n\n```js\nhotkeys.deleteScope('issues', 'newScopeName');\n```\n\n### unbind\n\nSimilar to defining shortcuts, they can be unbound using `hotkeys.unbind`.\n\n```js\n// unbind 'a' handler\nhotkeys.unbind('a');\n\n// Unbind a hotkeys only for a single scope\n// If no scope is specified it defaults to the current scope (hotkeys.getScope())\nhotkeys.unbind('o, enter', 'issues');\nhotkeys.unbind('o, enter', 'files');\n```\n\nUnbind events through functions.\n\n```js\nfunction example() {\n  hotkeys('a', example);\n  hotkeys.unbind('a', example);\n\n  hotkeys('a', 'issues', example);\n  hotkeys.unbind('a', 'issues', example);\n}\n```\n\nTo unbind everything.\n\n```js\nhotkeys.unbind();\n```\n\n### isPressed\n\nFor example, `hotkeys.isPressed(77)` is true if the `M` key is currently pressed.\n\n```js\nhotkeys('a', function() {\n  console.log(hotkeys.isPressed('a')); //=> true\n  console.log(hotkeys.isPressed('A')); //=> true\n  console.log(hotkeys.isPressed(65)); //=> true\n});\n```\n\n### trigger\n\ntrigger shortcut key event\n\n```js\nhotkeys.trigger('ctrl+o');\nhotkeys.trigger('ctrl+o', 'scope2');\n```\n\n### getPressedKeyCodes\n\nReturns an array of key codes currently pressed.\n\n```js\nhotkeys('command+ctrl+shift+a,f', function() {\n  console.log(hotkeys.getPressedKeyCodes()); //=> [17, 65] or [70]\n})\n```\n\n### getPressedKeyString\n\nReturns an array of key codes currently pressed.\n\n```js\nhotkeys('command+ctrl+shift+a,f', function() {\n  console.log(hotkeys.getPressedKeyString()); //=> ['⌘', '⌃', '⇧', 'A', 'F']\n})\n```\n\n### getAllKeyCodes\n\nGet a list of all registration codes.\n\n```js\nhotkeys('command+ctrl+shift+a,f', function() {\n  console.log(hotkeys.getAllKeyCodes());\n  // [\n  //   { scope: 'all', shortcut: 'command+ctrl+shift+a', mods: [91, 17, 16], keys: [91, 17, 16, 65] },\n  //   { scope: 'all', shortcut: 'f', mods: [], keys: [42] }\n  // ]\n})\n```\n\n### filter\n\nBy default hotkeys are not enabled for `INPUT` `SELECT` `TEXTAREA` elements. `Hotkeys.filter` to return to the `true` shortcut keys set to play a role, `false` shortcut keys set up failure.\n\n```js\nhotkeys.filter = function(event){\n  return true;\n}\n//How to add the filter to edit labels. <div contentEditable=\"true\"></div>\n//\"contentEditable\" Older browsers that do not support drops\nhotkeys.filter = function(event) {\n  var target = event.target || event.srcElement;\n  var tagName = target.tagName;\n  return !(target.isContentEditable || tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');\n}\n\nhotkeys.filter = function(event){\n  var tagName = (event.target || event.srcElement).tagName;\n  hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');\n  return true;\n}\n```\n\n### noConflict\n\nRelinquish HotKeys’s control of the `hotkeys` variable.\n\n```js\nvar k = hotkeys.noConflict();\nk('a', function() {\n  console.log(\"do something\")\n});\n\nhotkeys()\n// -->Uncaught TypeError: hotkeys is not a function(anonymous function)\n// @ VM2170:2InjectedScript._evaluateOn\n// @ VM2165:883InjectedScript._evaluateAndWrap\n// @ VM2165:816InjectedScript.evaluate @ VM2165:682\n```\n\n## Development\n\nTo develop, Install dependencies, Get the code:\n\n```shell\n$ git https://github.com/jaywcjlove/hotkeys.git\n$ cd hotkeys     # Into the directory\n$ npm install    # or  yarn install\n```\n\nTo develop, run the self-reloading build:\n\n```shell\n$ npm run watch\n```\n\nRun Document Website Environment.\n\n```shell\n$ npm run doc\n```\n\nTo contribute, please fork Hotkeys.js, add your patch and tests for it (in the `test/` folder) and submit a pull request.\n\n```shell\n$ npm run test\n$ npm run test:watch # Development model\n```\n\n## Contributors\n\nAs always, thanks to our amazing contributors!\n\n<a href=\"https://github.com/jaywcjlove/hotkeys-js/graphs/contributors\">\n  <img src=\"https://jaywcjlove.github.io/hotkeys-js/CONTRIBUTORS.svg\" />\n</a>\n\nMade with [github-action-contributors](https://github.com/jaywcjlove/github-action-contributors).\n\n## License\n\n[MIT © Kenny Wong](./LICENSE)\n","publish_time":1478971128096,"_cnpm_publish_time":1478971128096,"dist-tags":{"latest":"4.1.2"}}