├── .gitignore ├── README.md ├── package.json ├── LICENSE └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .tern-* 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # W3C keycode 2 | 3 | Tiny library that exports an object that maps numeric browser key 4 | codes to 5 | [`KeyEvent.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code) 6 | strings. The full list of such codes (of which this library only 7 | supports a subset) is defined in 8 | [this document](https://w3c.github.io/uievents-code/). 9 | 10 | License: MIT 11 | 12 | Does not try to target ancient browsers, and leaves out obscure keys. 13 | Intended to use as a reasonable fallback for browsers that don't have 14 | native support for `KeyEvent.code`. 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "w3c-keycode", 3 | "version": "1.0.0", 4 | "description": "Map KeyEvent.keyCode to KeyEvent.code-style strings", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/marijnh/w3c-keycode.git" 9 | }, 10 | "keywords": [ 11 | "browser", 12 | "key", 13 | "event", 14 | "key code" 15 | ], 16 | "author": "Marijn Haverbeke ", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/marijnh/w3c-keycode/issues" 20 | }, 21 | "homepage": "https://github.com/marijnh/w3c-keycode#readme" 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2016 by Marijn Haverbeke and others 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var keyCodes = module.exports = { 2 | 8: "Backspace", 3 | 9: "Tab", 4 | 10: "Enter", 5 | 12: "NumLock", 6 | 13: "Enter", 7 | 16: "Shift", 8 | 17: "Control", 9 | 18: "Alt", 10 | 20: "CapsLock", 11 | 27: "Escape", 12 | 32: "Space", 13 | 33: "PageUp", 14 | 34: "PageDown", 15 | 35: "End", 16 | 36: "Home", 17 | 37: "ArrowLeft", 18 | 38: "ArrowUp", 19 | 39: "ArrowRight", 20 | 40: "ArrowDown", 21 | 44: "PrintScreen", 22 | 45: "Insert", 23 | 46: "Delete", 24 | 59: "Semicolon", 25 | 61: "Equal", 26 | 91: "MetaLeft", 27 | 92: "MetaRight", 28 | 106: "NumpadMultiply", 29 | 107: "NumpadAdd", 30 | 108: "NumpadComma", 31 | 109: "NumpadSubtract", 32 | 110: "NumpadDecimal", 33 | 111: "NumpadDivide", 34 | 144: "NumLock", 35 | 145: "ScrollLock", 36 | 160: "ShiftLeft", 37 | 161: "ShiftRight", 38 | 162: "ControlLeft", 39 | 163: "ControlRight", 40 | 164: "AltLeft", 41 | 165: "AltRight", 42 | 173: "Minus", 43 | 186: "Semicolon", 44 | 187: "Equal", 45 | 188: "Comma", 46 | 189: "Minus", 47 | 190: "Period", 48 | 191: "Slash", 49 | 192: "Backquote", 50 | 219: "BracketLeft", 51 | 220: "Backslash", 52 | 221: "BracketRight", 53 | 222: "Quote" 54 | } 55 | 56 | for (var i = 0; i < 10; i++) { 57 | keyCodes[48 + i] = "Digit" + i 58 | keyCodes[96 + i] = "Numpad" + i 59 | } 60 | for (var i = 1; i <= 24; i++) 61 | keyCodes[i + 111] = "F" + i 62 | for (var i = 65; i <= 90; i++) 63 | keyCodes[i] = "Key" + String.fromCharCode(i) 64 | --------------------------------------------------------------------------------