{"id":21680288,"url":"https://github.com/matthewoden/keyevents-npm","last_synced_at":"2026-05-06T15:44:08.009Z","repository":{"id":27686646,"uuid":"31173051","full_name":"matthewoden/keyevents-npm","owner":"matthewoden","description":"a human readable event binding mixin for react.js","archived":false,"fork":false,"pushed_at":"2015-06-09T14:56:39.000Z","size":164,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T09:09:16.258Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/keyevents","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthewoden.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-22T18:07:39.000Z","updated_at":"2015-09-16T02:32:12.000Z","dependencies_parsed_at":"2022-08-29T10:50:19.137Z","dependency_job_id":null,"html_url":"https://github.com/matthewoden/keyevents-npm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewoden%2Fkeyevents-npm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewoden%2Fkeyevents-npm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewoden%2Fkeyevents-npm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewoden%2Fkeyevents-npm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthewoden","download_url":"https://codeload.github.com/matthewoden/keyevents-npm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244594173,"owners_count":20478215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T15:15:39.887Z","updated_at":"2026-05-06T15:44:02.960Z","avatar_url":"https://github.com/matthewoden.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"KeyEvents\n=========\n\nInstallation\n------------\n```bash\n$ npm install keyevents\n\n```\n\nUpgrading\n-----\nKeyEvents 2.0 is out! If you're not familiar with SemVer, that means you'll have to do some work to hop on the new version. See changes to componentKeyEvents below.\n\nUsage\n-----\n\nThis library takes the result of event.which, and returns the key in a human readable format (in english). It can be used as a mixin, or as a utility method (in case you're moving on to ES6 Classes). The main method, componentKeyEvents, runs on keydown, and returns the key assigned. The exact functionality is up to you.\n\n### Example (using an object lookup)\n\n``` js\nvar KeyEvents = require('keyevents');\n\nvar ExampleComponent = React.createComponent({\n  mixins:[KeyEvents],\n\n  componentKeyEvents:function(keypressed){\n\n     var ExampleObject = {\n      // You can assign functions directly:\n      a:function() {\n        console.log('you pressed a!')\n      },\n\n      backspace: function() {\n        console.log('back that space up!')\n      },\n\n      // ... or use component methods!\n      p: this.componentMethod(arguments)\n    }\n\n    ExampleObject[keypressed]();\n  }\n\n\n...\n\n```\n\nAgain, how you handle it is up to you. You could run through your keybindings as with a switch. You can also define all your keybindings in an external file, then share them components.\n\n### Methods\n\n#### this.componentKeyEvents()\nYour component's method for handling key presses. It's run on keyDown.\n\n#### this.destroyKeyEvents()\nthis removes all keydown event listners. When used as a mixin, it runs automatically on componentWillUnmount.\n\n#### this.createKeyEvents()\nthis initializes keydown event listeners. When used as a mixin, it runs automatically on componentWillMount.\n\n### Key Mapping\n\nThe keys included so far map as the following:\n``` js\n{\n  8 : 'backspace',\n  9 : 'tab',\n  13 : 'enter',\n  16 : 'shift',\n  17 : 'ctrl',\n  18 : 'alt',\n  19 : 'pause',\n  20 : 'capsLock',\n  27 : 'escape',\n  33 : 'pageUp',\n  34 : 'pageDown',\n  35 : 'end',\n  36 : 'home',\n  37 : 'left',\n  38 : 'up',\n  39 : 'right',\n  40 : 'down',\n  45 : 'insert',\n  46 : 'delete',\n  48 : '0',\n  49 : '1',\n  50 : '2',\n  51 : '3',\n  52 : '4',\n  53 : '5',\n  54 : '6',\n  55 : '7',\n  56 : '8',\n  57 : '9',\n  65 : 'a',\n  66 : 'b',\n  67 : 'c',\n  68 : 'd',\n  69 : 'e',\n  70 : 'f',\n  71 : 'g',\n  72 : 'h',\n  73 : 'i',\n  74 : 'j',\n  75 : 'k',\n  76 : 'l',\n  77 : 'm',\n  78 : 'n',\n  79 : 'o',\n  80 : 'p',\n  81 : 'q',\n  82 : 'r',\n  83 : 's',\n  84 : 't',\n  85 : 'u',\n  86 : 'v',\n  87 : 'w',\n  88 : 'x',\n  89 : 'y',\n  90 : 'z',\n  91 : 'leftWindowKey',\n  92 : 'rightWindowKey',\n  93 : 'select',\n  96 : 'numpad0',\n  97 : 'numpad1',\n  98 : 'numpad2',\n  99 : 'numpad3',\n  100 : 'numpad4',\n  101 : 'numpad5',\n  102 : 'numpad6',\n  103 : 'numpad7',\n  104 : 'numpad8',\n  105 : 'numpad9',\n  106 : 'multiply',\n  107 : 'add',\n  109 : 'subtract',\n  110 : 'decimal ',\n  111 : 'divide',\n  112 : 'f1',\n  113 : 'f2',\n  114 : 'f3',\n  115 : 'f4',\n  116 : 'f5',\n  117 : 'f6',\n  118 : 'f7',\n  119 : 'f8',\n  120 : 'f9',\n  121 : 'f10',\n  122 : 'f11',\n  123 : 'f12',\n  144 : 'numLock',\n  145 : 'scrollLock',\n  186 : ';',\n  187 : '=',\n  188 : ',',\n  189 : '-',\n  190 : '.',\n  191 : '/',\n  192 : '`',\n  219 : '{',\n  220 : '\\\\',\n  221 : '}',\n  22 : '\\''\n}\n\n```\n\n## Changelog\n- June 9th, 2015: Changed the functionality of ComponentKeyEvents to be an implementation detail.\n\n## Roadmap\n- Add in support for custom key dictionaries\n- Handle shift + Key, and general key combinations.\n\n## License\n[MIT](https://github.com/matthewoden/keyevents-npm/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewoden%2Fkeyevents-npm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthewoden%2Fkeyevents-npm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewoden%2Fkeyevents-npm/lists"}