33 lines
748 B
JavaScript
33 lines
748 B
JavaScript
const event = KeyboardEvent.prototype;
|
|
const descriptor = Object.getOwnPropertyDescriptor(event, 'key');
|
|
if (descriptor) {
|
|
const keys = {
|
|
Win: 'Meta',
|
|
Scroll: 'ScrollLock',
|
|
Spacebar: ' ',
|
|
|
|
Down: 'ArrowDown',
|
|
Left: 'ArrowLeft',
|
|
Right: 'ArrowRight',
|
|
Up: 'ArrowUp',
|
|
|
|
Del: 'Delete',
|
|
Apps: 'ContextMenu',
|
|
Esc: 'Escape',
|
|
|
|
Multiply: '*',
|
|
Add: '+',
|
|
Subtract: '-',
|
|
Decimal: '.',
|
|
Divide: '/',
|
|
};
|
|
Object.defineProperty(event, 'key', {
|
|
// eslint-disable-next-line object-shorthand, func-names
|
|
get: function () {
|
|
const key = descriptor.get.call(this);
|
|
|
|
// eslint-disable-next-line no-prototype-builtins
|
|
return keys.hasOwnProperty(key) ? keys[key] : key;
|
|
},
|
|
});
|
|
}
|