UNPKG

7.11 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7/**
8 * @ignore
9 * some key-codes definition and utils from closure-library
10 * @author yiminghe@gmail.com
11 */
12
13var KeyCode = {
14 /**
15 * MAC_ENTER
16 */
17 MAC_ENTER: 3,
18 /**
19 * BACKSPACE
20 */
21 BACKSPACE: 8,
22 /**
23 * TAB
24 */
25 TAB: 9,
26 /**
27 * NUMLOCK on FF/Safari Mac
28 */
29 NUM_CENTER: 12,
30 // NUMLOCK on FF/Safari Mac
31 /**
32 * ENTER
33 */
34 ENTER: 13,
35 /**
36 * SHIFT
37 */
38 SHIFT: 16,
39 /**
40 * CTRL
41 */
42 CTRL: 17,
43 /**
44 * ALT
45 */
46 ALT: 18,
47 /**
48 * PAUSE
49 */
50 PAUSE: 19,
51 /**
52 * CAPS_LOCK
53 */
54 CAPS_LOCK: 20,
55 /**
56 * ESC
57 */
58 ESC: 27,
59 /**
60 * SPACE
61 */
62 SPACE: 32,
63 /**
64 * PAGE_UP
65 */
66 PAGE_UP: 33,
67 // also NUM_NORTH_EAST
68 /**
69 * PAGE_DOWN
70 */
71 PAGE_DOWN: 34,
72 // also NUM_SOUTH_EAST
73 /**
74 * END
75 */
76 END: 35,
77 // also NUM_SOUTH_WEST
78 /**
79 * HOME
80 */
81 HOME: 36,
82 // also NUM_NORTH_WEST
83 /**
84 * LEFT
85 */
86 LEFT: 37,
87 // also NUM_WEST
88 /**
89 * UP
90 */
91 UP: 38,
92 // also NUM_NORTH
93 /**
94 * RIGHT
95 */
96 RIGHT: 39,
97 // also NUM_EAST
98 /**
99 * DOWN
100 */
101 DOWN: 40,
102 // also NUM_SOUTH
103 /**
104 * PRINT_SCREEN
105 */
106 PRINT_SCREEN: 44,
107 /**
108 * INSERT
109 */
110 INSERT: 45,
111 // also NUM_INSERT
112 /**
113 * DELETE
114 */
115 DELETE: 46,
116 // also NUM_DELETE
117 /**
118 * ZERO
119 */
120 ZERO: 48,
121 /**
122 * ONE
123 */
124 ONE: 49,
125 /**
126 * TWO
127 */
128 TWO: 50,
129 /**
130 * THREE
131 */
132 THREE: 51,
133 /**
134 * FOUR
135 */
136 FOUR: 52,
137 /**
138 * FIVE
139 */
140 FIVE: 53,
141 /**
142 * SIX
143 */
144 SIX: 54,
145 /**
146 * SEVEN
147 */
148 SEVEN: 55,
149 /**
150 * EIGHT
151 */
152 EIGHT: 56,
153 /**
154 * NINE
155 */
156 NINE: 57,
157 /**
158 * QUESTION_MARK
159 */
160 QUESTION_MARK: 63,
161 // needs localization
162 /**
163 * A
164 */
165 A: 65,
166 /**
167 * B
168 */
169 B: 66,
170 /**
171 * C
172 */
173 C: 67,
174 /**
175 * D
176 */
177 D: 68,
178 /**
179 * E
180 */
181 E: 69,
182 /**
183 * F
184 */
185 F: 70,
186 /**
187 * G
188 */
189 G: 71,
190 /**
191 * H
192 */
193 H: 72,
194 /**
195 * I
196 */
197 I: 73,
198 /**
199 * J
200 */
201 J: 74,
202 /**
203 * K
204 */
205 K: 75,
206 /**
207 * L
208 */
209 L: 76,
210 /**
211 * M
212 */
213 M: 77,
214 /**
215 * N
216 */
217 N: 78,
218 /**
219 * O
220 */
221 O: 79,
222 /**
223 * P
224 */
225 P: 80,
226 /**
227 * Q
228 */
229 Q: 81,
230 /**
231 * R
232 */
233 R: 82,
234 /**
235 * S
236 */
237 S: 83,
238 /**
239 * T
240 */
241 T: 84,
242 /**
243 * U
244 */
245 U: 85,
246 /**
247 * V
248 */
249 V: 86,
250 /**
251 * W
252 */
253 W: 87,
254 /**
255 * X
256 */
257 X: 88,
258 /**
259 * Y
260 */
261 Y: 89,
262 /**
263 * Z
264 */
265 Z: 90,
266 /**
267 * META
268 */
269 META: 91,
270 // WIN_KEY_LEFT
271 /**
272 * WIN_KEY_RIGHT
273 */
274 WIN_KEY_RIGHT: 92,
275 /**
276 * CONTEXT_MENU
277 */
278 CONTEXT_MENU: 93,
279 /**
280 * NUM_ZERO
281 */
282 NUM_ZERO: 96,
283 /**
284 * NUM_ONE
285 */
286 NUM_ONE: 97,
287 /**
288 * NUM_TWO
289 */
290 NUM_TWO: 98,
291 /**
292 * NUM_THREE
293 */
294 NUM_THREE: 99,
295 /**
296 * NUM_FOUR
297 */
298 NUM_FOUR: 100,
299 /**
300 * NUM_FIVE
301 */
302 NUM_FIVE: 101,
303 /**
304 * NUM_SIX
305 */
306 NUM_SIX: 102,
307 /**
308 * NUM_SEVEN
309 */
310 NUM_SEVEN: 103,
311 /**
312 * NUM_EIGHT
313 */
314 NUM_EIGHT: 104,
315 /**
316 * NUM_NINE
317 */
318 NUM_NINE: 105,
319 /**
320 * NUM_MULTIPLY
321 */
322 NUM_MULTIPLY: 106,
323 /**
324 * NUM_PLUS
325 */
326 NUM_PLUS: 107,
327 /**
328 * NUM_MINUS
329 */
330 NUM_MINUS: 109,
331 /**
332 * NUM_PERIOD
333 */
334 NUM_PERIOD: 110,
335 /**
336 * NUM_DIVISION
337 */
338 NUM_DIVISION: 111,
339 /**
340 * F1
341 */
342 F1: 112,
343 /**
344 * F2
345 */
346 F2: 113,
347 /**
348 * F3
349 */
350 F3: 114,
351 /**
352 * F4
353 */
354 F4: 115,
355 /**
356 * F5
357 */
358 F5: 116,
359 /**
360 * F6
361 */
362 F6: 117,
363 /**
364 * F7
365 */
366 F7: 118,
367 /**
368 * F8
369 */
370 F8: 119,
371 /**
372 * F9
373 */
374 F9: 120,
375 /**
376 * F10
377 */
378 F10: 121,
379 /**
380 * F11
381 */
382 F11: 122,
383 /**
384 * F12
385 */
386 F12: 123,
387 /**
388 * NUMLOCK
389 */
390 NUMLOCK: 144,
391 /**
392 * SEMICOLON
393 */
394 SEMICOLON: 186,
395 // needs localization
396 /**
397 * DASH
398 */
399 DASH: 189,
400 // needs localization
401 /**
402 * EQUALS
403 */
404 EQUALS: 187,
405 // needs localization
406 /**
407 * COMMA
408 */
409 COMMA: 188,
410 // needs localization
411 /**
412 * PERIOD
413 */
414 PERIOD: 190,
415 // needs localization
416 /**
417 * SLASH
418 */
419 SLASH: 191,
420 // needs localization
421 /**
422 * APOSTROPHE
423 */
424 APOSTROPHE: 192,
425 // needs localization
426 /**
427 * SINGLE_QUOTE
428 */
429 SINGLE_QUOTE: 222,
430 // needs localization
431 /**
432 * OPEN_SQUARE_BRACKET
433 */
434 OPEN_SQUARE_BRACKET: 219,
435 // needs localization
436 /**
437 * BACKSLASH
438 */
439 BACKSLASH: 220,
440 // needs localization
441 /**
442 * CLOSE_SQUARE_BRACKET
443 */
444 CLOSE_SQUARE_BRACKET: 221,
445 // needs localization
446 /**
447 * WIN_KEY
448 */
449 WIN_KEY: 224,
450 /**
451 * MAC_FF_META
452 */
453 MAC_FF_META: 224,
454 // Firefox (Gecko) fires this for the meta key instead of 91
455 /**
456 * WIN_IME
457 */
458 WIN_IME: 229,
459 // ======================== Function ========================
460 /**
461 * whether text and modified key is entered at the same time.
462 */
463 isTextModifyingKeyEvent: function isTextModifyingKeyEvent(e) {
464 var keyCode = e.keyCode;
465 if (e.altKey && !e.ctrlKey || e.metaKey ||
466 // Function keys don't generate text
467 keyCode >= KeyCode.F1 && keyCode <= KeyCode.F12) {
468 return false;
469 }
470
471 // The following keys are quite harmless, even in combination with
472 // CTRL, ALT or SHIFT.
473 switch (keyCode) {
474 case KeyCode.ALT:
475 case KeyCode.CAPS_LOCK:
476 case KeyCode.CONTEXT_MENU:
477 case KeyCode.CTRL:
478 case KeyCode.DOWN:
479 case KeyCode.END:
480 case KeyCode.ESC:
481 case KeyCode.HOME:
482 case KeyCode.INSERT:
483 case KeyCode.LEFT:
484 case KeyCode.MAC_FF_META:
485 case KeyCode.META:
486 case KeyCode.NUMLOCK:
487 case KeyCode.NUM_CENTER:
488 case KeyCode.PAGE_DOWN:
489 case KeyCode.PAGE_UP:
490 case KeyCode.PAUSE:
491 case KeyCode.PRINT_SCREEN:
492 case KeyCode.RIGHT:
493 case KeyCode.SHIFT:
494 case KeyCode.UP:
495 case KeyCode.WIN_KEY:
496 case KeyCode.WIN_KEY_RIGHT:
497 return false;
498 default:
499 return true;
500 }
501 },
502 /**
503 * whether character is entered.
504 */
505 isCharacterKey: function isCharacterKey(keyCode) {
506 if (keyCode >= KeyCode.ZERO && keyCode <= KeyCode.NINE) {
507 return true;
508 }
509 if (keyCode >= KeyCode.NUM_ZERO && keyCode <= KeyCode.NUM_MULTIPLY) {
510 return true;
511 }
512 if (keyCode >= KeyCode.A && keyCode <= KeyCode.Z) {
513 return true;
514 }
515
516 // Safari sends zero key code for non-latin characters.
517 if (window.navigator.userAgent.indexOf('WebKit') !== -1 && keyCode === 0) {
518 return true;
519 }
520 switch (keyCode) {
521 case KeyCode.SPACE:
522 case KeyCode.QUESTION_MARK:
523 case KeyCode.NUM_PLUS:
524 case KeyCode.NUM_MINUS:
525 case KeyCode.NUM_PERIOD:
526 case KeyCode.NUM_DIVISION:
527 case KeyCode.SEMICOLON:
528 case KeyCode.DASH:
529 case KeyCode.EQUALS:
530 case KeyCode.COMMA:
531 case KeyCode.PERIOD:
532 case KeyCode.SLASH:
533 case KeyCode.APOSTROPHE:
534 case KeyCode.SINGLE_QUOTE:
535 case KeyCode.OPEN_SQUARE_BRACKET:
536 case KeyCode.BACKSLASH:
537 case KeyCode.CLOSE_SQUARE_BRACKET:
538 return true;
539 default:
540 return false;
541 }
542 }
543};
544var _default = exports.default = KeyCode;
\No newline at end of file