Library that returns a list of KeyboardEvent codes based the input keyCode
npm install keycode-to-codes
Library that returns a list of possible KeyboardEvent codes based the input keyCode.
Useful for replacing a missing KeyboardEvent.code property.
Example:
13 -> ["Enter", "NumpadEnter"] \
32 -> ["Space"] \
97 -> ["KeyA"]
Add the script to your project through a package manager:
$ npm i keycode-to-codes
or
$ yarn add keycode-to-codes
Alternatively you can also import the script found in the releases section on GitHub directly. If you choose this option you won't need to use imports going forward - everything will all be available to you automatically.
``html`
Or include through a public CDN:
`html`
`javascript
import keyCodeToCodes from 'keycode-to-codes';
// OR
const keyCodeToCodes = require('keycode-to-codes');
window.addEventListener('keypress', (event) => {
const codes = keyCodeToCodes(event.keyCode);
});
``