Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created April 9, 2020 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathantneal/89c6f0342e50e6203ba24f47f04d3bb9 to your computer and use it in GitHub Desktop.
Save jonathantneal/89c6f0342e50e6203ba24f47f04d3bb9 to your computer and use it in GitHub Desktop.
KeyboardEvent Key: Polyfill the correct key names in Internet Explorer (577 bytes / 385 bytes gzipped)
!function () {
let KeyboardEventPrototype = KeyboardEvent.prototype
let KeyboardEventPrototypeKeyDescriptor = Object.getOwnPropertyDescriptor(KeyboardEventPrototype, 'key')
let KeyboardEventPrototypeKeyGetter = KeyboardEventPrototypeKeyDescriptor.get
KeyboardEventPrototypeKeyDescriptor.get = function () {
return {
27: 'Escape',
29: 'NonConvert',
32: ' ',
37: 'ArrowLeft',
38: 'ArrowUp',
39: 'ArrowRight',
40: 'ArrowDown',
46: 'Delete',
72: 'AudioVolumeUp',
73: 'AudioVolumeDown',
74: 'AudioVolumeMute',
91: 'Meta',
92: 'Meta',
93: 'ContextMenu',
95: 'Standby',
145: 'ScrollLock',
176: 'MediaTrackNext',
177: 'MediaTrackPrevious',
181: 'LaunchMediaPlayer',
229: 'Process',
240: 'Attn',
241: 'Finish',
244: 'Zenkaku',
247: 'CrSel',
248: 'ExSel',
251: 'ZoomToggle'
}[this.which] || KeyboardEventPrototypeKeyGetter.call(this)
}
Object.defineProperty(KeyboardEventPrototype, 'key', KeyboardEventPrototypeKeyDescriptor)
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment