polyfill for `KeyboardEvent.prototype.key`
npm install keyboardevent-key-polyfillPolyfill for KeyboardEvent.prototype.key.
> NOTE: All major browsers now support KeyboardEvent.prototype.key. Firefox already shipped with this for a while; recent versions of Edge, Chrome, and Safari also now have shipped support. This will still enable KeyboardEvent.prototype.key in environments where it may not yet be available.
__View Demo__
Say goodbye to this:
``js`
document.addEventListener('keydown', function (e) {
console.log('Code of key pressed:', e.which || e.keyCode); // 39
});
And hello to this:
`js`
document.addEventListener('keydown', function (e) {
console.log('Name of key pressed:', e.key); // ArrowRight
});
Just drop the script on your page and call the polyfill method.
`html`
If you're using AMD:
`js`
require('keyboardevent-key-polyfill').polyfill();
Install from npm:
`bash`
npm install keyboardevent-key-polyfill
Then require the CommonJS module for use with Browserify/webpack:
`js``
require('keyboardevent-key-polyfill').polyfill();
All code and content within this source-code repository is licensed under the Creative Commons Zero v1.0 Universal license (CC0 1.0 Universal; Public Domain Dedication).
You can copy, modify, distribute and perform this work, even for commercial purposes, all without asking permission.
For more information, refer to these following links:
* a copy of the license in this source-code repository
* the human-readable summary of the full text of the legal code
* the full text of the legal code