Created
April 9, 2020 14:33
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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