https://github.com/cvan/keyboardevent-key-polyfill
polyfill for `KeyboardEvent.prototype.key`
https://github.com/cvan/keyboardevent-key-polyfill
Last synced: 10 months ago
JSON representation
polyfill for `KeyboardEvent.prototype.key`
- Host: GitHub
- URL: https://github.com/cvan/keyboardevent-key-polyfill
- Owner: cvan
- License: cc0-1.0
- Created: 2015-06-04T07:52:08.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-08-10T15:03:19.000Z (almost 8 years ago)
- Last Synced: 2024-12-17T22:13:01.810Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://cvan.io/keyboardevent-key-polyfill/
- Size: 17.6 KB
- Stars: 47
- Watchers: 2
- Forks: 15
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# keyboardevent-key-polyfill
Polyfill for `KeyboardEvent.prototype.key`.
> **NOTE:** All major browsers [now support `KeyboardEvent.prototype.key`](http://caniuse.com/#feat=keyboardevent-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.
## Example
__[View Demo](https://cvan.io/keyboardevent-key-polyfill/)__
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
});
```
## Usage
### From standalone script
Just drop the script on your page and call the `polyfill` method.
```html
keyboardeventKeyPolyfill.polyfill();
```
If you're using AMD:
```js
require('keyboardevent-key-polyfill').polyfill();
```
### From npm (Node/Browserify/WebPack)
Install from [npm](https://www.npmjs.com/package/keyboardevent-key-polyfill):
```bash
npm install keyboardevent-key-polyfill
```
Then require the CommonJS module for use with [Browserify](http://browserify.org)/[webpack](https://webpack.js.org/):
```js
require('keyboardevent-key-polyfill').polyfill();
```
## License
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)](LICENSE.md).
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](LICENSE.md) in [this source-code repository](https://github.com/cvan/keyboardevent-key-polyfill)
* the [human-readable summary](https://creativecommons.org/publicdomain/zero/1.0/) of the [full text of the legal code](https://creativecommons.org/publicdomain/zero/1.0/legalcode)
* the [full text of the legal code](https://creativecommons.org/publicdomain/zero/1.0/legalcode)