{"name":"hotkeys-js","description":"A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.","version":"3.10.0","main":"index.js","types":"index.d.ts","module":"dist/hotkeys.esm.js","scripts":{"prepare":"npm run build:lib && husky install","lint":"eslint --ext .js src website","build:lib":"node scripts/build.js","build":"npm run build:lib && npm run doc && npm run lint","watch":"node scripts/watch.js","pretest":"npm run build","test":"jest --coverage --detectOpenHandles","test:watch":"jest --watch","doc":"kkt build --app-src ./website","start":"kkt start --app-src ./website"},"keywords":["hotkey","hotkeys","hotkeys-js","hotkeysjs","key","keys","keyboard","shortcuts","keypress"],"author":{"name":"kenny wong","email":"wowohoo@qq.com"},"license":"MIT","homepage":"http://jaywcjlove.github.io/hotkeys","repository":{"type":"git","url":"git+https://github.com/jaywcjlove/hotkeys.git"},"jest":{"testURL":"http://localhost/"},"devDependencies":{"@babel/eslint-parser":"^7.18.9","@kkt/less-modules":"^7.2.0","@kkt/raw-modules":"^7.2.0","@kkt/scope-plugin-options":"^7.2.0","@rollup/plugin-babel":"~5.3.1","@rollup/plugin-commonjs":"~22.0.2","@rollup/plugin-node-resolve":"~13.3.0","@uiw/react-github-corners":"~1.5.14","@uiw/react-mac-keyboard":"~1.1.4","@uiw/react-markdown-preview":"~4.0.24","@uiw/react-shields":"~1.1.3","@wcj/dark-mode":"~1.0.15","bannerjs":"~2.1.0","classnames":"~2.3.1","colors-cli":"~1.0.28","eslint":"~8.22.0","eslint-config-airbnb":"~19.0.4","eslint-plugin-import":"~2.26.0","eslint-plugin-jsx-a11y":"~6.6.1","eslint-plugin-react":"~7.30.1","husky":"~8.0.1","jest":"~27.5.1","kkt":"^7.2.0","lint-staged":"~13.0.3","puppeteer":"~13.5.2","react":"~18.2.0","react-dom":"~18.2.0","rimraf":"~3.0.2","rollup":"~2.78.1","uglify-js":"~3.17.0","zlib":"~1.0.5"},"browserslist":{"production":[">0.2%","not dead","not op_mini all"],"development":["last 1 chrome version","last 1 firefox version","last 1 safari version"]},"lint-staged":{"*.js":"eslint --ext .js src website"},"gitHead":"db269a920fe6e8e8689945ff67f636d8174b174e","bugs":{"url":"https://github.com/jaywcjlove/hotkeys/issues"},"_id":"hotkeys-js@3.10.0","_nodeVersion":"16.17.0","_npmVersion":"8.15.0","dist":{"integrity":"sha512-20xeVdOqcgTkMox0+BqFwADZP7+5dy/9CFPpAinSMh2d0s3b0Hs2V2D+lMh4Hphkf7VE9pwnOl58eP1te+REcg==","shasum":"2bbd13de4aa002fa916c34e3859239924311e35a","tarball":"http://registry-npm.ywwl.com/hotkeys-js/download/hotkeys-js-3.10.0.tgz","fileCount":11,"unpackedSize":83082,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCySCY45+aimWCYVugnOY+A6BUGezQq98zNBgJDoCqqXAIgTvuI9Ws/0+xML/tSSyTXOvwJ8FvlA96aupu9zKFQOVQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjGFMJACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoPgA/9ESAP6HsyTnrwl3eHt0z8c6j9pGqOBf8B1/GLIFol8yy+8RED\r\nt/6LVy3ObDApTMF71VKcG/UEq/PgYjvEtBptVcnaK184PxTsHVjiNvN7+KaK\r\nz2q/jwJy19Oq7MPUsY2EfX4VLnYS88+Z4l+gT8IyGJZ8QwVc7UqSMIlX6knR\r\nzOisxuF/5nkt5fGtLUCqo+VHGSJ9KwWMEqEYlnVB3LckrfXK/aPz1lkQ6iA0\r\nbxcLuUc3FnjY378NmoHHX2NwIksdwZHonPwI0xKtLIpabpfDRRjKyyUUlsuZ\r\ntdL/vlUA86AC+tE72UZuirSTU3UMTEjgYWElqhOV/kCce2m9WNScCP4aQU9Y\r\njLYgR+oGVIbp5UGFS9VCh/bieOrLk+nLccXO0cxUXCObkR0xjckjXRmAMDwC\r\nSaKFFgbknUP0UuJCnLQp/b36rvPvjNilqLsS430STTkTboiADIxr2fK474nx\r\nHm1ePUr/R1MB0CSg4wHSAgLLUzTqmFAADrAlmN6ey0Pyef8f5CHs1lYGtUcA\r\nT7dtlmwOuguDvwMlmGJvQYyTORxE7SIImUI8Zb/B6HuXvGakwLDgjcm8eZKx\r\nJL0T8Qk3Vwtk2DNM1Mk1Ji2dlJHc5SL9UNvXvgOzH2a1Vimz47dmimg1TbLO\r\n7Pu66L4Pa0lrfhN5++538Xm1+Pn8hzX7heU=\r\n=ADgM\r\n-----END PGP SIGNATURE-----\r\n","size":19186,"noattachment":false,"key":"/hotkeys-js/-/hotkeys-js-3.10.0.tgz"},"_npmUser":{"name":"wcjiang","email":"398188662@qq.com"},"directories":{},"maintainers":[{"name":"wcjiang","email":"398188662@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hotkeys-js_3.10.0_1662538504980_0.7216174766322558"},"_hasShrinkwrap":false,"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":1662538505163,"_cnpm_publish_time":1662538505163,"dist-tags":{"latest":"4.1.2"}}