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