Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/donmccurdy/keyboardevent-key-polyfill
polyfill for `KeyboardEvent.prototype.key`
https://github.com/donmccurdy/keyboardevent-key-polyfill
Last synced: 2 days ago
JSON representation
polyfill for `KeyboardEvent.prototype.key`
- Host: GitHub
- URL: https://github.com/donmccurdy/keyboardevent-key-polyfill
- Owner: donmccurdy
- License: mit
- Fork: true (cvan/keyboardevent-key-polyfill)
- Created: 2016-02-07T05:10:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2015-12-23T11:49:31.000Z (almost 9 years ago)
- Last Synced: 2023-04-09T19:47:45.861Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://cvan.io/keyboardevent-key-polyfill/
- Size: 6.84 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# keyboardevent-key-polyfill
Polyfill for `KeyboardEvent.prototype.key`.
Firefox has already shipped with this for a while, but this will normalise it for other browsers (e.g., Chrome).
## 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/WebPack:
```js
require('keyboardevent-key-polyfill').polyfill();
```## License
[MIT](LICENCSE)