Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/public/js/keyboard.polyfill.js
7432 views
1
/* global define, KeyboardEvent, module */
2
3
(function () {
4
5
var keyboardeventKeyPolyfill = {
6
polyfill: polyfill,
7
keys: {
8
3: 'Cancel',
9
6: 'Help',
10
8: 'Backspace',
11
9: 'Tab',
12
12: 'Clear',
13
13: 'Enter',
14
16: 'Shift',
15
17: 'Control',
16
18: 'Alt',
17
19: 'Pause',
18
20: 'CapsLock',
19
27: 'Escape',
20
28: 'Convert',
21
29: 'NonConvert',
22
30: 'Accept',
23
31: 'ModeChange',
24
32: ' ',
25
33: 'PageUp',
26
34: 'PageDown',
27
35: 'End',
28
36: 'Home',
29
37: 'ArrowLeft',
30
38: 'ArrowUp',
31
39: 'ArrowRight',
32
40: 'ArrowDown',
33
41: 'Select',
34
42: 'Print',
35
43: 'Execute',
36
44: 'PrintScreen',
37
45: 'Insert',
38
46: 'Delete',
39
48: ['0', ')'],
40
49: ['1', '!'],
41
50: ['2', '@'],
42
51: ['3', '#'],
43
52: ['4', '$'],
44
53: ['5', '%'],
45
54: ['6', '^'],
46
55: ['7', '&'],
47
56: ['8', '*'],
48
57: ['9', '('],
49
91: 'OS',
50
93: 'ContextMenu',
51
144: 'NumLock',
52
145: 'ScrollLock',
53
181: 'VolumeMute',
54
182: 'VolumeDown',
55
183: 'VolumeUp',
56
186: [';', ':'],
57
187: ['=', '+'],
58
188: [',', '<'],
59
189: ['-', '_'],
60
190: ['.', '>'],
61
191: ['/', '?'],
62
192: ['`', '~'],
63
219: ['[', '{'],
64
220: ['\\', '|'],
65
221: [']', '}'],
66
222: ["'", '"'],
67
224: 'Meta',
68
225: 'AltGraph',
69
246: 'Attn',
70
247: 'CrSel',
71
248: 'ExSel',
72
249: 'EraseEof',
73
250: 'Play',
74
251: 'ZoomOut'
75
}
76
};
77
78
// Function keys (F1-24).
79
var i;
80
for (i = 1; i < 25; i++) {
81
keyboardeventKeyPolyfill.keys[111 + i] = 'F' + i;
82
}
83
84
// Printable ASCII characters.
85
var letter = '';
86
for (i = 65; i < 91; i++) {
87
letter = String.fromCharCode(i);
88
keyboardeventKeyPolyfill.keys[i] = [letter.toLowerCase(), letter.toUpperCase()];
89
}
90
91
function polyfill () {
92
if (!('KeyboardEvent' in window) ||
93
'key' in KeyboardEvent.prototype) {
94
return false;
95
}
96
97
// Polyfill `key` on `KeyboardEvent`.
98
var proto = {
99
get: function (x) {
100
var key = keyboardeventKeyPolyfill.keys[this.which || this.keyCode];
101
102
if (Array.isArray(key)) {
103
key = key[+this.shiftKey];
104
}
105
106
return key;
107
}
108
};
109
Object.defineProperty(KeyboardEvent.prototype, 'key', proto);
110
return proto;
111
}
112
113
if (typeof define === 'function' && define.amd) {
114
define('keyboardevent-key-polyfill', keyboardeventKeyPolyfill);
115
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
116
module.exports = keyboardeventKeyPolyfill;
117
} else if (window) {
118
window.keyboardeventKeyPolyfill = keyboardeventKeyPolyfill;
119
}
120
121
})();
122
123