OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [java/] [awt/] [event/] [KeyEvent.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* KeyEvent.java -- event for key presses
2
   Copyright (C) 1999, 2002, 2004, 2005  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package java.awt.event;
40
 
41
import gnu.java.awt.EventModifier;
42
 
43
import java.awt.Component;
44
import java.io.IOException;
45
import java.io.ObjectInputStream;
46
 
47
/**
48
 * This event is generated when a key is pressed or released. There are two
49
 * categories of key events:
50
 *
51
 * <p><em>"Key typed" events</em> are higher-level, and have already
52
 * compensated for modifiers and keyboard layout to generate a single Unicode
53
 * character. It may take several key press events to generate one key typed.
54
 * The <code>getKeyCode</code> method will return <code>VK_UNDEFINED</code>,
55
 * and <code>getKeyChar</code> will return a valid Unicode character or
56
 * <code>CHAR_UNDEFINED</code>.
57
 *
58
 * <p><em>"Key pressed" and "key released" events</em> are lower-level, and
59
 * are platform and keyboard dependent. They correspond to the actaul motion
60
 * on a keyboard, and return a virtual key code which labels the key that was
61
 * pressed. The <code>getKeyCode</code> method will return one of the
62
 * <code>VK_*</code> constants (except VK_UNDEFINED), and the
63
 * <code>getKeyChar</code> method is undefined.
64
 *
65
 * <p>Some keys do not generate key typed events, such as the F1 or HELP keys.
66
 * Not all keyboards can generate all virtual keys, and no attempt is made to
67
 * simulate the ones that can't be typed. Virtual keys correspond to the
68
 * keyboard layout, so for example, VK_Q in English is VK_A in French. Also,
69
 * there are some additional virtual keys to ease handling of actions, such
70
 * as VK_ALL_CANDIDATES in place of ALT+VK_CONVERT. Do not rely on the value
71
 * of the VK_* constants, except for VK_ENTER, VK_BACK_SPACE, and VK_TAB.
72
 *
73
 * @author Aaron M. Renn (arenn@urbanophile.com)
74
 * @author Eric Blake (ebb9@email.byu.edu)
75
 * @see KeyAdapter
76
 * @see KeyListener
77
 * @since 1.1
78
 * @status updated to 1.4
79
 */
80
public class KeyEvent extends InputEvent
81
{
82
  /**
83
   * Compatible with JDK 1.1+.
84
   */
85
  private static final long serialVersionUID = -2352130953028126954L;
86
 
87
  /** This is the first id in the range of event ids used by this class. */
88
  public static final int KEY_FIRST = 400;
89
 
90
  /** This is the last id in the range of event ids used by this class. */
91
  public static final int KEY_LAST = 402;
92
 
93
  /**
94
   * This event id indicates a key was typed, which is a key press followed
95
   * by a key release to generate an actual Unicode character. It may take
96
   * several key presses to generate one key typed event, and some action
97
   * keys have no corresponding key typed.
98
   */
99
  public static final int KEY_TYPED = 400;
100
 
101
  /** This event id indicates a key was pressed. */
102
  public static final int KEY_PRESSED = 401;
103
 
104
  /** This event it indicates a key was released. */
105
  public static final int KEY_RELEASED = 402;
106
 
107
  /** The virtual key Enter, which will always map to '\n'. */
108
  public static final int VK_ENTER = '\n';
109
 
110
  /** The virtual key Backspace, which will always map to '\b'. */
111
  public static final int VK_BACK_SPACE = '\b';
112
 
113
  /** The virtual key Tab, which will always map to '\t'. */
114
  public static final int VK_TAB = '\t';
115
 
116
  /** The virtual key Cancel. */
117
  public static final int VK_CANCEL = 3;
118
 
119
  /** The virtual key VK_CLEAR. */
120
  public static final int VK_CLEAR = 12;
121
 
122
  /** The virtual key VK_SHIFT. */
123
  public static final int VK_SHIFT = 16;
124
 
125
  /** The virtual key VK_CONTROL. */
126
  public static final int VK_CONTROL = 17;
127
 
128
  /** The virtual key VK_ALT. */
129
  public static final int VK_ALT = 18;
130
 
131
  /** The virtual key VK_PAUSE. */
132
  public static final int VK_PAUSE = 19;
133
 
134
  /** The virtual key VK_CAPS_LOCK. */
135
  public static final int VK_CAPS_LOCK = 20;
136
 
137
  /** The virtual key VK_ESCAPE. */
138
  public static final int VK_ESCAPE = 27;
139
 
140
  /** The virtual key VK_SPACE. */
141
  public static final int VK_SPACE = ' ';
142
 
143
  /** The virtual key VK_PAGE_UP. */
144
  public static final int VK_PAGE_UP = 33;
145
 
146
  /** The virtual key VK_PAGE_DOWN. */
147
  public static final int VK_PAGE_DOWN = 34;
148
 
149
  /** The virtual key VK_END. */
150
  public static final int VK_END = 35;
151
 
152
  /** The virtual key VK_HOME. */
153
  public static final int VK_HOME = 36;
154
 
155
  /**
156
   * The virtual key for the non-numpad VK_LEFT.
157
   *
158
   * @see #VK_KP_LEFT
159
   */
160
  public static final int VK_LEFT = 37;
161
 
162
  /**
163
   * The virtual key for the non-numpad VK_UP.
164
   *
165
   * @see #VK_KP_UP
166
   */
167
  public static final int VK_UP = 38;
168
 
169
  /**
170
   * The virtual key for the non-numpad VK_RIGHT.
171
   *
172
   * @see #VK_KP_RIGHT
173
   */
174
  public static final int VK_RIGHT = 39;
175
 
176
  /**
177
   * The virtual key for the non-numpad VK_DOWN.
178
   *
179
   * @see #VK_KP_DOWN
180
   */
181
  public static final int VK_DOWN = 40;
182
 
183
  /** The virtual key VK_COMMA. */
184
  public static final int VK_COMMA = ',';
185
 
186
  /**
187
   * The virtual key VK_MINUS.
188
   *
189
   * @since 1.2
190
   */
191
  public static final int VK_MINUS = '-';
192
 
193
  /** The virtual key VK_PERIOD. */
194
  public static final int VK_PERIOD = '.';
195
 
196
  /** The virtual key VK_SLASH. */
197
  public static final int VK_SLASH = '/';
198
 
199
  /** The virtual key VK_0. */
200
  public static final int VK_0 = '0';
201
 
202
  /** The virtual key VK_1. */
203
  public static final int VK_1 = '1';
204
 
205
  /** The virtual key VK_2. */
206
  public static final int VK_2 = '2';
207
 
208
  /** The virtual key VK_3. */
209
  public static final int VK_3 = '3';
210
 
211
  /** The virtual key VK_4. */
212
  public static final int VK_4 = '4';
213
 
214
  /** The virtual key VK_5. */
215
  public static final int VK_5 = '5';
216
 
217
  /** The virtual key VK_6. */
218
  public static final int VK_6 = '6';
219
 
220
  /** The virtual key VK_7. */
221
  public static final int VK_7 = '7';
222
 
223
  /** The virtual key VK_8. */
224
  public static final int VK_8 = '8';
225
 
226
  /** The virtual key VK_9. */
227
  public static final int VK_9 = '9';
228
 
229
  /** The virtual key VK_SEMICOLON. */
230
  public static final int VK_SEMICOLON = ';';
231
 
232
  /** The virtual key VK_EQUALS. */
233
  public static final int VK_EQUALS = '=';
234
 
235
  /** The virtual key VK_A. */
236
  public static final int VK_A = 'A';
237
 
238
  /** The virtual key VK_B. */
239
  public static final int VK_B = 'B';
240
 
241
  /** The virtual key VK_C. */
242
  public static final int VK_C = 'C';
243
 
244
  /** The virtual key VK_D. */
245
  public static final int VK_D = 'D';
246
 
247
  /** The virtual key VK_E. */
248
  public static final int VK_E = 'E';
249
 
250
  /** The virtual key VK_F. */
251
  public static final int VK_F = 'F';
252
 
253
  /** The virtual key VK_G. */
254
  public static final int VK_G = 'G';
255
 
256
  /** The virtual key VK_H. */
257
  public static final int VK_H = 'H';
258
 
259
  /** The virtual key VK_I. */
260
  public static final int VK_I = 'I';
261
 
262
  /** The virtual key VK_J. */
263
  public static final int VK_J = 'J';
264
 
265
  /** The virtual key VK_K. */
266
  public static final int VK_K = 'K';
267
 
268
  /** The virtual key VK_L. */
269
  public static final int VK_L = 'L';
270
 
271
  /** The virtual key VK_M. */
272
  public static final int VK_M = 'M';
273
 
274
  /** The virtual key VK_N. */
275
  public static final int VK_N = 'N';
276
 
277
  /** The virtual key VK_O. */
278
  public static final int VK_O = 'O';
279
 
280
  /** The virtual key VK_P. */
281
  public static final int VK_P = 'P';
282
 
283
  /** The virtual key VK_Q. */
284
  public static final int VK_Q = 'Q';
285
 
286
  /** The virtual key VK_R. */
287
  public static final int VK_R = 'R';
288
 
289
  /** The virtual key VK_S. */
290
  public static final int VK_S = 'S';
291
 
292
  /** The virtual key VK_T. */
293
  public static final int VK_T = 'T';
294
 
295
  /** The virtual key VK_U. */
296
  public static final int VK_U = 'U';
297
 
298
  /** The virtual key VK_V. */
299
  public static final int VK_V = 'V';
300
 
301
  /** The virtual key VK_W. */
302
  public static final int VK_W = 'W';
303
 
304
  /** The virtual key VK_X. */
305
  public static final int VK_X = 'X';
306
 
307
  /** The virtual key VK_Y. */
308
  public static final int VK_Y = 'Y';
309
 
310
  /** The virtual key VK_Z. */
311
  public static final int VK_Z = 'Z';
312
 
313
  /** The virtual key VK_OPEN_BRACKET. */
314
  public static final int VK_OPEN_BRACKET = '[';
315
 
316
  /** The virtual key VK_BACK_SLASH. */
317
  public static final int VK_BACK_SLASH = '\\';
318
 
319
  /** The virtual key VK_CLOSE_BRACKET. */
320
  public static final int VK_CLOSE_BRACKET = ']';
321
 
322
  /** The virtual key VK_NUMPAD0. */
323
  public static final int VK_NUMPAD0 = 96;
324
 
325
  /** The virtual key VK_NUMPAD1. */
326
  public static final int VK_NUMPAD1 = 97;
327
 
328
  /** The virtual key VK_NUMPAD2. */
329
  public static final int VK_NUMPAD2 = 98;
330
 
331
  /** The virtual key VK_NUMPAD3. */
332
  public static final int VK_NUMPAD3 = 99;
333
 
334
  /** The virtual key VK_NUMPAD4. */
335
  public static final int VK_NUMPAD4 = 100;
336
 
337
  /** The virtual key VK_NUMPAD5. */
338
  public static final int VK_NUMPAD5 = 101;
339
 
340
  /** The virtual key VK_NUMPAD6. */
341
  public static final int VK_NUMPAD6 = 102;
342
 
343
  /** The virtual key VK_NUMPAD7. */
344
  public static final int VK_NUMPAD7 = 103;
345
 
346
  /** The virtual key VK_NUMPAD8. */
347
  public static final int VK_NUMPAD8 = 104;
348
 
349
  /** The virtual key VK_NUMPAD9. */
350
  public static final int VK_NUMPAD9 = 105;
351
 
352
  /** The virtual key VK_MULTIPLY. */
353
  public static final int VK_MULTIPLY = 106;
354
 
355
  /** The virtual key VK_ADD. */
356
  public static final int VK_ADD = 107;
357
 
358
  /**
359
   * The virtual key VK_SEPARATOR, handily mispelled for those who can't
360
   * figure it out.
361
   *
362
   * @deprecated use {@link #VK_SEPARATOR}
363
   */
364
  public static final int VK_SEPARATER = 108;
365
 
366
  /**
367
   * The virtual key VK_SEPARATOR.
368
   *
369
   * @since 1.4
370
   */
371
  public static final int VK_SEPARATOR = 108;
372
 
373
  /** The virtual key VK_SUBTRACT. */
374
  public static final int VK_SUBTRACT = 109;
375
 
376
  /** The virtual key VK_DECIMAL. */
377
  public static final int VK_DECIMAL = 110;
378
 
379
  /** The virtual key VK_DIVIDE. */
380
  public static final int VK_DIVIDE = 111;
381
 
382
  /** The virtual key VK_DELETE. */
383
  public static final int VK_DELETE = 127;
384
 
385
  /** The virtual key VK_NUM_LOCK. */
386
  public static final int VK_NUM_LOCK = 144;
387
 
388
  /** The virtual key VK_SCROLL_LOCK. */
389
  public static final int VK_SCROLL_LOCK = 145;
390
 
391
  /** The virtual key VK_F1. */
392
  public static final int VK_F1 = 112;
393
 
394
  /** The virtual key VK_F2. */
395
  public static final int VK_F2 = 113;
396
 
397
  /** The virtual key VK_F3. */
398
  public static final int VK_F3 = 114;
399
 
400
  /** The virtual key VK_F4. */
401
  public static final int VK_F4 = 115;
402
 
403
  /** The virtual key VK_F5. */
404
  public static final int VK_F5 = 116;
405
 
406
  /** The virtual key VK_F6. */
407
  public static final int VK_F6 = 117;
408
 
409
  /** The virtual key VK_F7. */
410
  public static final int VK_F7 = 118;
411
 
412
  /** The virtual key VK_F8. */
413
  public static final int VK_F8 = 119;
414
 
415
  /** The virtual key VK_F9. */
416
  public static final int VK_F9 = 120;
417
 
418
  /** The virtual key VK_F10. */
419
  public static final int VK_F10 = 121;
420
 
421
  /** The virtual key VK_F11. */
422
  public static final int VK_F11 = 122;
423
 
424
  /** The virtual key VK_F12. */
425
  public static final int VK_F12 = 123;
426
 
427
  /**
428
   * The virtual key VK_F13.
429
   *
430
   * @since 1.2
431
   */
432
  public static final int VK_F13 = 61440;
433
 
434
  /**
435
   * The virtual key VK_F14.
436
   *
437
   * @since 1.2
438
   */
439
  public static final int VK_F14 = 61441;
440
 
441
  /**
442
   * The virtual key VK_F15.
443
   *
444
   * @since 1.2
445
   */
446
  public static final int VK_F15 = 61442;
447
 
448
  /**
449
   * The virtual key VK_F16.
450
   *
451
   * @since 1.2
452
   */
453
  public static final int VK_F16 = 61443;
454
 
455
  /**
456
   * The virtual key VK_F17.
457
   *
458
   * @since 1.2
459
   */
460
  public static final int VK_F17 = 61444;
461
 
462
  /**
463
   * The virtual key VK_F18.
464
   *
465
   * @since 1.2
466
   */
467
  public static final int VK_F18 = 61445;
468
 
469
  /**
470
   * The virtual key VK_F19.
471
   *
472
   * @since 1.2
473
   */
474
  public static final int VK_F19 = 61446;
475
 
476
  /**
477
   * The virtual key VK_F20.
478
   *
479
   * @since 1.2
480
   */
481
  public static final int VK_F20 = 61447;
482
 
483
  /**
484
   * The virtual key VK_F21.
485
   *
486
   * @since 1.2
487
   */
488
  public static final int VK_F21 = 61448;
489
 
490
  /**
491
   * The virtual key VK_F22.
492
   *
493
   * @since 1.2
494
   */
495
  public static final int VK_F22 = 61449;
496
 
497
  /**
498
   * The virtual key VK_F23.
499
   *
500
   * @since 1.2
501
   */
502
  public static final int VK_F23 = 61450;
503
 
504
  /**
505
   * The virtual key VK_F24.
506
   *
507
   * @since 1.2
508
   */
509
  public static final int VK_F24 = 61451;
510
 
511
  /** The virtual key VK_PRINTSCREEN. */
512
  public static final int VK_PRINTSCREEN = 154;
513
 
514
  /** The virtual key VK_INSERT. */
515
  public static final int VK_INSERT = 155;
516
 
517
  /** The virtual key VK_HELP. */
518
  public static final int VK_HELP = 156;
519
 
520
  /** The virtual key VK_META. */
521
  public static final int VK_META = 157;
522
 
523
  /** The virtual key VK_BACK_QUOTE. */
524
  public static final int VK_BACK_QUOTE = 192;
525
 
526
  /** The virtual key VK_QUOTE. */
527
  public static final int VK_QUOTE = 222;
528
 
529
  /**
530
   * The virtual key for the numpad VK_KP_UP.
531
   *
532
   * @see #VK_UP
533
   * @since 1.2
534
   */
535
  public static final int VK_KP_UP = 224;
536
 
537
  /**
538
   * The virtual key for the numpad VK_KP_DOWN.
539
   *
540
   * @see #VK_DOWN
541
   * @since 1.2
542
   */
543
  public static final int VK_KP_DOWN = 225;
544
 
545
  /**
546
   * The virtual key for the numpad VK_KP_LEFT.
547
   *
548
   * @see #VK_LEFT
549
   * @since 1.2
550
   */
551
  public static final int VK_KP_LEFT = 226;
552
 
553
  /**
554
   * The virtual key for the numpad VK_KP_RIGHT.
555
   *
556
   * @see #VK_RIGHT
557
   * @since 1.2
558
   */
559
  public static final int VK_KP_RIGHT = 227;
560
 
561
  /**
562
   * The virtual key VK_DEAD_GRAVE.
563
   *
564
   * @since 1.2
565
   */
566
  public static final int VK_DEAD_GRAVE = 128;
567
 
568
  /**
569
   * The virtual key VK_DEAD_ACUTE.
570
   *
571
   * @since 1.2
572
   */
573
  public static final int VK_DEAD_ACUTE = 129;
574
 
575
  /**
576
   * The virtual key VK_DEAD_CIRCUMFLEX.
577
   *
578
   * @since 1.2
579
   */
580
  public static final int VK_DEAD_CIRCUMFLEX = 130;
581
 
582
  /**
583
   * The virtual key VK_DEAD_TILDE.
584
   *
585
   * @since 1.2
586
   */
587
  public static final int VK_DEAD_TILDE = 131;
588
 
589
  /**
590
   * The virtual key VK_DEAD_MACRON.
591
   *
592
   * @since 1.2
593
   */
594
  public static final int VK_DEAD_MACRON = 132;
595
 
596
  /**
597
   * The virtual key VK_DEAD_BREVE.
598
   *
599
   * @since 1.2
600
   */
601
  public static final int VK_DEAD_BREVE = 133;
602
 
603
  /**
604
   * The virtual key VK_DEAD_ABOVEDOT.
605
   *
606
   * @since 1.2
607
   */
608
  public static final int VK_DEAD_ABOVEDOT = 134;
609
 
610
  /**
611
   * The virtual key VK_DEAD_DIAERESIS.
612
   *
613
   * @since 1.2
614
   */
615
  public static final int VK_DEAD_DIAERESIS = 135;
616
 
617
  /**
618
   * The virtual key VK_DEAD_ABOVERING.
619
   *
620
   * @since 1.2
621
   */
622
  public static final int VK_DEAD_ABOVERING = 136;
623
 
624
  /**
625
   * The virtual key VK_DEAD_DOUBLEACUTE.
626
   *
627
   * @since 1.2
628
   */
629
  public static final int VK_DEAD_DOUBLEACUTE = 137;
630
 
631
  /**
632
   * The virtual key VK_DEAD_CARON.
633
   *
634
   * @since 1.2
635
   */
636
  public static final int VK_DEAD_CARON = 138;
637
 
638
  /**
639
   * The virtual key VK_DEAD_CEDILLA.
640
   *
641
   * @since 1.2
642
   */
643
  public static final int VK_DEAD_CEDILLA = 139;
644
 
645
  /**
646
   * The virtual key VK_DEAD_OGONEK.
647
   *
648
   * @since 1.2
649
   */
650
  public static final int VK_DEAD_OGONEK = 140;
651
 
652
  /**
653
   * The virtual key VK_DEAD_IOTA.
654
   *
655
   * @since 1.2
656
   */
657
  public static final int VK_DEAD_IOTA = 141;
658
 
659
  /**
660
   * The virtual key VK_DEAD_VOICED_SOUND.
661
   *
662
   * @since 1.2
663
   */
664
  public static final int VK_DEAD_VOICED_SOUND = 142;
665
 
666
  /**
667
   * The virtual key VK_DEAD_SEMIVOICED_SOUND.
668
   *
669
   * @since 1.2
670
   */
671
  public static final int VK_DEAD_SEMIVOICED_SOUND = 143;
672
 
673
  /**
674
   * The virtual key VK_AMPERSAND.
675
   *
676
   * @since 1.2
677
   */
678
  public static final int VK_AMPERSAND = 150;
679
 
680
  /**
681
   * The virtual key VK_ASTERISK.
682
   *
683
   * @since 1.2
684
   */
685
  public static final int VK_ASTERISK = 151;
686
 
687
  /**
688
   * The virtual key VK_QUOTEDBL.
689
   *
690
   * @since 1.2
691
   */
692
  public static final int VK_QUOTEDBL = 152;
693
 
694
  /**
695
   * The virtual key VK_LESS.
696
   *
697
   * @since 1.2
698
   */
699
  public static final int VK_LESS = 153;
700
 
701
  /**
702
   * The virtual key VK_GREATER.
703
   *
704
   * @since 1.2
705
   */
706
  public static final int VK_GREATER = 160;
707
 
708
  /**
709
   * The virtual key VK_BRACELEFT.
710
   *
711
   * @since 1.2
712
   */
713
  public static final int VK_BRACELEFT = 161;
714
 
715
  /**
716
   * The virtual key VK_BRACERIGHT.
717
   *
718
   * @since 1.2
719
   */
720
  public static final int VK_BRACERIGHT = 162;
721
 
722
  /**
723
   * The virtual key VK_AT.
724
   *
725
   * @since 1.2
726
   */
727
  public static final int VK_AT = 512;
728
 
729
  /**
730
   * The virtual key VK_COLON.
731
   *
732
   * @since 1.2
733
   */
734
  public static final int VK_COLON = 513;
735
 
736
  /**
737
   * The virtual key VK_CIRCUMFLEX.
738
   *
739
   * @since 1.2
740
   */
741
  public static final int VK_CIRCUMFLEX = 514;
742
 
743
  /**
744
   * The virtual key VK_DOLLAR.
745
   *
746
   * @since 1.2
747
   */
748
  public static final int VK_DOLLAR = 515;
749
 
750
  /**
751
   * The virtual key VK_EURO_SIGN.
752
   *
753
   * @since 1.2
754
   */
755
  public static final int VK_EURO_SIGN = 516;
756
 
757
  /**
758
   * The virtual key VK_EXCLAMATION_MARK.
759
   *
760
   * @since 1.2
761
   */
762
  public static final int VK_EXCLAMATION_MARK = 517;
763
 
764
  /**
765
   * The virtual key VK_INVERTED_EXCLAMATION_MARK.
766
   *
767
   * @since 1.2
768
   */
769
  public static final int VK_INVERTED_EXCLAMATION_MARK = 518;
770
 
771
  /**
772
   * The virtual key VK_LEFT_PARENTHESIS.
773
   *
774
   * @since 1.2
775
   */
776
  public static final int VK_LEFT_PARENTHESIS = 519;
777
 
778
  /**
779
   * The virtual key VK_NUMBER_SIGN.
780
   *
781
   * @since 1.2
782
   */
783
  public static final int VK_NUMBER_SIGN = 520;
784
 
785
  /**
786
   * The virtual key VK_PLUS.
787
   *
788
   * @since 1.2
789
   */
790
  public static final int VK_PLUS = 521;
791
 
792
  /**
793
   * The virtual key VK_RIGHT_PARENTHESIS.
794
   *
795
   * @since 1.2
796
   */
797
  public static final int VK_RIGHT_PARENTHESIS = 522;
798
 
799
  /**
800
   * The virtual key VK_UNDERSCORE.
801
   *
802
   * @since 1.2
803
   */
804
  public static final int VK_UNDERSCORE = 523;
805
 
806
  /** The virtual key VK_FINAL. */
807
  public static final int VK_FINAL = 24;
808
 
809
  /** The virtual key VK_CONVERT. */
810
  public static final int VK_CONVERT = 28;
811
 
812
  /** The virtual key VK_NONCONVERT. */
813
  public static final int VK_NONCONVERT = 29;
814
 
815
  /** The virtual key VK_ACCEPT. */
816
  public static final int VK_ACCEPT = 30;
817
 
818
  /** The virtual key VK_MODECHANGE. */
819
  public static final int VK_MODECHANGE = 31;
820
 
821
  /** The virtual key VK_KANA. */
822
  public static final int VK_KANA = 21;
823
 
824
  /** The virtual key VK_KANJI. */
825
  public static final int VK_KANJI = 25;
826
 
827
  /**
828
   * The virtual key VK_ALPHANUMERIC.
829
   *
830
   * @since 1.2
831
   */
832
  public static final int VK_ALPHANUMERIC = 240;
833
 
834
  /**
835
   * The virtual key VK_KATAKANA.
836
   *
837
   * @since 1.2
838
   */
839
  public static final int VK_KATAKANA = 241;
840
 
841
  /**
842
   * The virtual key VK_HIRAGANA.
843
   *
844
   * @since 1.2
845
   */
846
  public static final int VK_HIRAGANA = 242;
847
 
848
  /**
849
   * The virtual key VK_FULL_WIDTH.
850
   *
851
   * @since 1.2
852
   */
853
  public static final int VK_FULL_WIDTH = 243;
854
 
855
  /**
856
   * The virtual key VK_HALF_WIDTH.
857
   *
858
   * @since 1.2
859
   */
860
  public static final int VK_HALF_WIDTH = 244;
861
 
862
  /**
863
   * The virtual key VK_ROMAN_CHARACTERS.
864
   *
865
   * @since 1.2
866
   */
867
  public static final int VK_ROMAN_CHARACTERS = 245;
868
 
869
  /**
870
   * The virtual key VK_ALL_CANDIDATES.
871
   *
872
   * @since 1.2
873
   */
874
  public static final int VK_ALL_CANDIDATES = 256;
875
 
876
  /**
877
   * The virtual key VK_PREVIOUS_CANDIDATE.
878
   *
879
   * @since 1.2
880
   */
881
  public static final int VK_PREVIOUS_CANDIDATE = 257;
882
 
883
  /**
884
   * The virtual key VK_CODE_INPUT.
885
   *
886
   * @since 1.2
887
   */
888
  public static final int VK_CODE_INPUT = 258;
889
 
890
  /**
891
   * The virtual key VK_JAPANESE_KATAKANA.
892
   *
893
   * @since 1.2
894
   */
895
  public static final int VK_JAPANESE_KATAKANA = 259;
896
 
897
  /**
898
   * The virtual key VK_JAPANESE_HIRAGANA.
899
   *
900
   * @since 1.2
901
   */
902
  public static final int VK_JAPANESE_HIRAGANA = 260;
903
 
904
  /**
905
   * The virtual key VK_JAPANESE_ROMAN.
906
   *
907
   * @since 1.2
908
   */
909
  public static final int VK_JAPANESE_ROMAN = 261;
910
 
911
  /**
912
   * The virtual key VK_KANA_LOCK.
913
   *
914
   * @since 1.3
915
   */
916
  public static final int VK_KANA_LOCK = 262;
917
 
918
  /**
919
   * The virtual key VK_INPUT_METHOD_ON_OFF.
920
   *
921
   * @since 1.3
922
   */
923
  public static final int VK_INPUT_METHOD_ON_OFF = 263;
924
 
925
  /**
926
   * The virtual key VK_CUT.
927
   *
928
   * @since 1.2
929
   */
930
  public static final int VK_CUT = 65489;
931
 
932
  /**
933
   * The virtual key VK_COPY.
934
   *
935
   * @since 1.2
936
   */
937
  public static final int VK_COPY = 65485;
938
 
939
  /**
940
   * The virtual key VK_PASTE.
941
   *
942
   * @since 1.2
943
   */
944
  public static final int VK_PASTE = 65487;
945
 
946
  /**
947
   * The virtual key VK_UNDO.
948
   *
949
   * @since 1.2
950
   */
951
  public static final int VK_UNDO = 65483;
952
 
953
  /**
954
   * The virtual key VK_AGAIN.
955
   *
956
   * @since 1.2
957
   */
958
  public static final int VK_AGAIN = 65481;
959
 
960
  /**
961
   * The virtual key VK_FIND.
962
   *
963
   * @since 1.2
964
   */
965
  public static final int VK_FIND = 65488;
966
 
967
  /**
968
   * The virtual key VK_PROPS.
969
   *
970
   * @since 1.2
971
   */
972
  public static final int VK_PROPS = 65482;
973
 
974
  /**
975
   * The virtual key VK_STOP.
976
   *
977
   * @since 1.2
978
   */
979
  public static final int VK_STOP = 65480;
980
 
981
  /**
982
   * The virtual key VK_COMPOSE.
983
   *
984
   * @since 1.2
985
   */
986
  public static final int VK_COMPOSE = 65312;
987
 
988
  /**
989
   * The virtual key VK_ALT_GRAPH.
990
   *
991
   * @since 1.2
992
   */
993
  public static final int VK_ALT_GRAPH = 65406;
994
 
995
  /**
996
   * The virtual key VK_UNDEFINED. This is used for key typed events, which
997
   * do not have a virtual key.
998
   */
999
  public static final int VK_UNDEFINED = 0;
1000
 
1001
  /**
1002
   * The only char with no valid Unicode interpretation. This is used for
1003
   * key pressed and key released events which do not have a valid keyChar.
1004
   */
1005
  public static final char CHAR_UNDEFINED = '\uffff';
1006
 
1007
  /**
1008
   * Indicates unknown or irrelavent key location. This is also used for
1009
   * key typed events, which do not need a location.
1010
   *
1011
   * @since 1.4
1012
   */
1013
  public static final int KEY_LOCATION_UNKNOWN = 0;
1014
 
1015
  /**
1016
   * Indicates a standard key location, with no left/right variants and not
1017
   * on the numeric pad.
1018
   *
1019
   * @since 1.4
1020
   */
1021
  public static final int KEY_LOCATION_STANDARD = 1;
1022
 
1023
  /**
1024
   * Indicates the key is on the left side of the keyboard, such as the left
1025
   * shift.
1026
   *
1027
   * @since 1.4
1028
   */
1029
  public static final int KEY_LOCATION_LEFT = 2;
1030
 
1031
  /**
1032
   * Indicates the key is on the right side of the keyboard, such as the right
1033
   * shift.
1034
   *
1035
   * @since 1.4
1036
   */
1037
  public static final int KEY_LOCATION_RIGHT = 3;
1038
 
1039
  /**
1040
   * Indicates the key is on the numeric pad, such as the numpad 0.
1041
   *
1042
   * @since 1.4
1043
   */
1044
  public static final int KEY_LOCATION_NUMPAD = 4;
1045
 
1046
  /**
1047
   * The code assigned to the physical keyboard location (as adjusted by the
1048
   * keyboard layout). Use the symbolic VK_* names instead of numbers.
1049
   *
1050
   * @see #getKeyCode()
1051
   * @serial the VK_ code for this key
1052
  */
1053
  private int keyCode;
1054
 
1055
  /**
1056
   * The Unicode character produced by the key type event. This has no meaning
1057
   * for key pressed and key released events.
1058
   *
1059
   * @see #getKeyChar()
1060
   * @serial the Unicode value for this key
1061
   */
1062
  private char keyChar;
1063
 
1064
  /**
1065
   * The keyboard location of the key. One of {@link #KEY_LOCATION_UNKNOWN},
1066
   * {@link #KEY_LOCATION_STANDARD}, {@link #KEY_LOCATION_LEFT},
1067
   * {@link #KEY_LOCATION_RIGHT}, or {@link #KEY_LOCATION_NUMPAD}.
1068
   *
1069
   * @see #getKeyLocation()
1070
   * @serial the key location
1071
   * @since 1.4
1072
   */
1073
  private final int keyLocation;
1074
 
1075
  /**
1076
   * Stores the state of the native event dispatching system, to correctly
1077
   * dispatch in Component#dispatchEventImpl when a proxy is active.
1078
   *
1079
   * XXX Does this matter in Classpath?
1080
   *
1081
   * @serial whether the proxy is active
1082
   */
1083
  private boolean isProxyActive;
1084
 
1085
 
1086
  /**
1087
   * Initializes a new instance of <code>KeyEvent</code> with the specified
1088
   * information. Note that an invalid id leads to unspecified results.
1089
   *
1090
   * @param source the component that generated this event
1091
   * @param id the event id
1092
   * @param when the timestamp when the even occurred
1093
   * @param modifiers the modifier keys during the event, in old or new style
1094
   * @param keyCode the integer constant for the virtual key type
1095
   * @param keyChar the Unicode value of the key
1096
   * @param keyLocation the location of the key
1097
   * @throws IllegalArgumentException if source is null, if keyLocation is
1098
   *         invalid, or if (id == KEY_TYPED && (keyCode != VK_UNDEFINED
1099
   *         || keyChar == CHAR_UNDEFINED))
1100
   */
1101
  public KeyEvent(Component source, int id, long when, int modifiers,
1102
                  int keyCode, char keyChar, int keyLocation)
1103
  {
1104
    super(source, id, when, modifiers);
1105
    this.keyCode = keyCode;
1106
    this.keyChar = keyChar;
1107
    this.keyLocation = keyLocation;
1108
    if ((id == KEY_TYPED && (keyCode != VK_UNDEFINED
1109
                             || keyChar == CHAR_UNDEFINED))
1110
        || keyLocation < KEY_LOCATION_UNKNOWN
1111
        || keyLocation > KEY_LOCATION_NUMPAD)
1112
      throw new IllegalArgumentException();
1113
  }
1114
 
1115
  /**
1116
   * Initializes a new instance of <code>KeyEvent</code> with the specified
1117
   * information. Note that an invalid id leads to unspecified results.
1118
   *
1119
   * @param source the component that generated this event
1120
   * @param id the event id
1121
   * @param when the timestamp when the even occurred
1122
   * @param modifiers the modifier keys during the event, in old or new style
1123
   * @param keyCode the integer constant for the virtual key type
1124
   * @param keyChar the Unicode value of the key
1125
   * @throws IllegalArgumentException if source is null, or if
1126
   *         (id == KEY_TYPED && (keyCode != VK_UNDEFINED
1127
   *         || keyChar == CHAR_UNDEFINED))
1128
   */
1129
  public KeyEvent(Component source, int id, long when, int modifiers,
1130
                  int keyCode, char keyChar)
1131
  {
1132
    this(source, id, when, modifiers, keyCode, keyChar, KEY_LOCATION_UNKNOWN);
1133
  }
1134
 
1135
  /**
1136
   * Initializes a new instance of <code>KeyEvent</code> with the specified
1137
   * information. Note that an invalid id leads to unspecified results.
1138
   *
1139
   * @param source the component that generated this event
1140
   * @param id the event id
1141
   * @param when the timestamp when the even occurred
1142
   * @param modifiers the modifier keys during the event, in old or new style
1143
   * @param keyCode the integer constant for the virtual key type
1144
   * @throws IllegalArgumentException if source is null, or if
1145
   *         id == KEY_TYPED but keyCode != VK_UNDEFINED
1146
   *
1147
   * @deprecated
1148
   */
1149
  public KeyEvent(Component source, int id, long when, int modifiers,
1150
                  int keyCode)
1151
  {
1152
    this(source, id, when, modifiers, keyCode, '\0', KEY_LOCATION_UNKNOWN);
1153
  }
1154
 
1155
  /**
1156
   * Returns the key code for the event key.  This will be one of the
1157
   * <code>VK_*</code> constants defined in this class. If the event type is
1158
   * KEY_TYPED, the result will be VK_UNDEFINED.
1159
   *
1160
   * @return the key code for this event
1161
   */
1162
  public int getKeyCode()
1163
  {
1164
    return keyCode;
1165
  }
1166
 
1167
  /**
1168
   * Sets the key code for this event.  This must be one of the
1169
   * <code>VK_*</code> constants defined in this class.
1170
   *
1171
   * @param keyCode the new key code for this event
1172
   */
1173
  public void setKeyCode(int keyCode)
1174
  {
1175
    this.keyCode = keyCode;
1176
  }
1177
 
1178
  /**
1179
   * Returns the Unicode value for the event key.  This will be
1180
   * <code>CHAR_UNDEFINED</code> if there is no Unicode equivalent for
1181
   * this key, usually when this is a KEY_PRESSED or KEY_RELEASED event.
1182
   *
1183
   * @return the Unicode character for this event
1184
   */
1185
  public char getKeyChar()
1186
  {
1187
    return keyChar;
1188
  }
1189
 
1190
  /**
1191
   * Sets the Unicode character for this event to the specified value.
1192
   *
1193
   * @param keyChar the new Unicode character for this event
1194
   */
1195
  public void setKeyChar(char keyChar)
1196
  {
1197
    this.keyChar = keyChar;
1198
  }
1199
 
1200
  /**
1201
   * Sets the modifier keys to the specified value. This should be a union
1202
   * of the bit mask constants from <code>InputEvent</code>. The use of this
1203
   * method is not recommended, particularly for KEY_TYPED events, which do
1204
   * not check if the modifiers were changed.
1205
   *
1206
   * @param modifiers the new modifier value, in either old or new style
1207
   * @see InputEvent
1208
   *
1209
   * @deprecated
1210
   */
1211
  public void setModifiers(int modifiers)
1212
  {
1213
    this.modifiers = EventModifier.extend(modifiers);
1214
  }
1215
 
1216
  /**
1217
   * Returns the keyboard location of the key that generated this event. This
1218
   * provides a way to distinguish between keys like left and right shift
1219
   * which share a common key code. The result will be one of
1220
   * {@link #KEY_LOCATION_UNKNOWN}, {@link #KEY_LOCATION_STANDARD},
1221
   * {@link #KEY_LOCATION_LEFT}, {@link #KEY_LOCATION_RIGHT}, or
1222
   * {@link #KEY_LOCATION_NUMPAD}.
1223
   *
1224
   * @return the key location
1225
   * @since 1.4
1226
   */
1227
  public int getKeyLocation()
1228
  {
1229
    return keyLocation;
1230
  }
1231
 
1232
  /**
1233
   * Returns the text name of key code, such as "HOME", "F1", or "A".
1234
   *
1235
   * XXX Sun claims this can be localized via the awt.properties file - how
1236
   * do we implement that?
1237
   *
1238
   * @return the text name of the key code
1239
   */
1240
  public static String getKeyText(int keyCode)
1241
  {
1242
    switch (keyCode)
1243
      {
1244
      case VK_CANCEL:
1245
        return "Cancel";
1246
      case VK_BACK_SPACE:
1247
        return "Backspace";
1248
      case VK_TAB:
1249
        return "Tab";
1250
      case VK_ENTER:
1251
        return "Enter";
1252
      case VK_CLEAR:
1253
        return "Clear";
1254
      case VK_SHIFT:
1255
        return "Shift";
1256
      case VK_CONTROL:
1257
        return "Ctrl";
1258
      case VK_ALT:
1259
        return "Alt";
1260
      case VK_PAUSE:
1261
        return "Pause";
1262
      case VK_CAPS_LOCK:
1263
        return "Caps Lock";
1264
      case VK_KANA:
1265
        return "Kana";
1266
      case VK_FINAL:
1267
        return "Final";
1268
      case VK_KANJI:
1269
        return "Kanji";
1270
      case VK_ESCAPE:
1271
        return "Escape";
1272
      case VK_CONVERT:
1273
        return "Convert";
1274
      case VK_NONCONVERT:
1275
        return "No Convert";
1276
      case VK_ACCEPT:
1277
        return "Accept";
1278
      case VK_MODECHANGE:
1279
        return "Mode Change";
1280
      case VK_SPACE:
1281
        return "Space";
1282
      case VK_PAGE_UP:
1283
        return "Page Up";
1284
      case VK_PAGE_DOWN:
1285
        return "Page Down";
1286
      case VK_END:
1287
        return "End";
1288
      case VK_HOME:
1289
        return "Home";
1290
      case VK_LEFT:
1291
      case VK_KP_LEFT:
1292
        return "Left";
1293
      case VK_UP:
1294
      case VK_KP_UP:
1295
        return "Up";
1296
      case VK_RIGHT:
1297
      case VK_KP_RIGHT:
1298
        return "Right";
1299
      case VK_DOWN:
1300
      case VK_KP_DOWN:
1301
        return "Down";
1302
      case VK_MINUS:
1303
        return "Minus";
1304
      case VK_MULTIPLY:
1305
        return "NumPad *";
1306
      case VK_ADD:
1307
        return "NumPad +";
1308
      case VK_SEPARATOR:
1309
        return "NumPad ,";
1310
      case VK_SUBTRACT:
1311
        return "NumPad -";
1312
      case VK_DECIMAL:
1313
        return "NumPad .";
1314
      case VK_DIVIDE:
1315
        return "NumPad /";
1316
      case VK_DELETE:
1317
        return "Delete";
1318
      case VK_DEAD_GRAVE:
1319
        return "Dead Grave";
1320
      case VK_DEAD_ACUTE:
1321
        return "Dead Acute";
1322
      case VK_DEAD_CIRCUMFLEX:
1323
        return "Dead Circumflex";
1324
      case VK_DEAD_TILDE:
1325
        return "Dead Tilde";
1326
      case VK_DEAD_MACRON:
1327
        return "Dead Macron";
1328
      case VK_DEAD_BREVE:
1329
        return "Dead Breve";
1330
      case VK_DEAD_ABOVEDOT:
1331
        return "Dead Above Dot";
1332
      case VK_DEAD_DIAERESIS:
1333
        return "Dead Diaeresis";
1334
      case VK_DEAD_ABOVERING:
1335
        return "Dead Above Ring";
1336
      case VK_DEAD_DOUBLEACUTE:
1337
        return "Dead Double Acute";
1338
      case VK_DEAD_CARON:
1339
        return "Dead Caron";
1340
      case VK_DEAD_CEDILLA:
1341
        return "Dead Cedilla";
1342
      case VK_DEAD_OGONEK:
1343
        return "Dead Ogonek";
1344
      case VK_DEAD_IOTA:
1345
        return "Dead Iota";
1346
      case VK_DEAD_VOICED_SOUND:
1347
        return "Dead Voiced Sound";
1348
      case VK_DEAD_SEMIVOICED_SOUND:
1349
        return "Dead Semivoiced Sound";
1350
      case VK_NUM_LOCK:
1351
        return "Num Lock";
1352
      case VK_SCROLL_LOCK:
1353
        return "Scroll Lock";
1354
      case VK_AMPERSAND:
1355
        return "Ampersand";
1356
      case VK_ASTERISK:
1357
        return "Asterisk";
1358
      case VK_QUOTEDBL:
1359
        return "Double Quote";
1360
      case VK_LESS:
1361
        return "Less";
1362
      case VK_PRINTSCREEN:
1363
        return "Print Screen";
1364
      case VK_INSERT:
1365
        return "Insert";
1366
      case VK_HELP:
1367
        return "Help";
1368
      case VK_META:
1369
        return "Meta";
1370
      case VK_GREATER:
1371
        return "Greater";
1372
      case VK_BRACELEFT:
1373
        return "Left Brace";
1374
      case VK_BRACERIGHT:
1375
        return "Right Brace";
1376
      case VK_BACK_QUOTE:
1377
        return "Back Quote";
1378
      case VK_QUOTE:
1379
        return "Quote";
1380
      case VK_ALPHANUMERIC:
1381
        return "Alphanumeric";
1382
      case VK_KATAKANA:
1383
        return "Katakana";
1384
      case VK_HIRAGANA:
1385
        return "Hiragana";
1386
      case VK_FULL_WIDTH:
1387
        return "Full-Width";
1388
      case VK_HALF_WIDTH:
1389
        return "Half-Width";
1390
      case VK_ROMAN_CHARACTERS:
1391
        return "Roman Characters";
1392
      case VK_ALL_CANDIDATES:
1393
        return "All Candidates";
1394
      case VK_PREVIOUS_CANDIDATE:
1395
        return "Previous Candidate";
1396
      case VK_CODE_INPUT:
1397
        return "Code Input";
1398
      case VK_JAPANESE_KATAKANA:
1399
        return "Japanese Katakana";
1400
      case VK_JAPANESE_HIRAGANA:
1401
        return "Japanese Hiragana";
1402
      case VK_JAPANESE_ROMAN:
1403
        return "Japanese Roman";
1404
      case VK_KANA_LOCK:
1405
        return "Kana Lock";
1406
      case VK_INPUT_METHOD_ON_OFF:
1407
        return "Input Method On/Off";
1408
      case VK_AT:
1409
        return "At";
1410
      case VK_COLON:
1411
        return "Colon";
1412
      case VK_CIRCUMFLEX:
1413
        return "Circumflex";
1414
      case VK_DOLLAR:
1415
        return "Dollar";
1416
      case VK_EURO_SIGN:
1417
        return "Euro";
1418
      case VK_EXCLAMATION_MARK:
1419
        return "Exclamation Mark";
1420
      case VK_INVERTED_EXCLAMATION_MARK:
1421
        return "Inverted Exclamation Mark";
1422
      case VK_LEFT_PARENTHESIS:
1423
        return "Left Parenthesis";
1424
      case VK_NUMBER_SIGN:
1425
        return "Number Sign";
1426
      case VK_PLUS:
1427
        return "Plus";
1428
      case VK_RIGHT_PARENTHESIS:
1429
        return "Right Parenthesis";
1430
      case VK_UNDERSCORE:
1431
        return "Underscore";
1432
      case VK_COMPOSE:
1433
        return "Compose";
1434
      case VK_ALT_GRAPH:
1435
        return "Alt Graph";
1436
      case VK_STOP:
1437
        return "Stop";
1438
      case VK_AGAIN:
1439
        return "Again";
1440
      case VK_PROPS:
1441
        return "Props";
1442
      case VK_UNDO:
1443
        return "Undo";
1444
      case VK_COPY:
1445
        return "Copy";
1446
      case VK_PASTE:
1447
        return "Paste";
1448
      case VK_FIND:
1449
        return "Find";
1450
      case VK_CUT:
1451
        return "Cut";
1452
      case VK_COMMA:
1453
      case VK_PERIOD:
1454
      case VK_SLASH:
1455
      case VK_0:
1456
      case VK_1:
1457
      case VK_2:
1458
      case VK_3:
1459
      case VK_4:
1460
      case VK_5:
1461
      case VK_6:
1462
      case VK_7:
1463
      case VK_8:
1464
      case VK_9:
1465
      case VK_SEMICOLON:
1466
      case VK_EQUALS:
1467
      case VK_A:
1468
      case VK_B:
1469
      case VK_C:
1470
      case VK_D:
1471
      case VK_E:
1472
      case VK_F:
1473
      case VK_G:
1474
      case VK_H:
1475
      case VK_I:
1476
      case VK_J:
1477
      case VK_K:
1478
      case VK_L:
1479
      case VK_M:
1480
      case VK_N:
1481
      case VK_O:
1482
      case VK_P:
1483
      case VK_Q:
1484
      case VK_R:
1485
      case VK_S:
1486
      case VK_T:
1487
      case VK_U:
1488
      case VK_V:
1489
      case VK_W:
1490
      case VK_X:
1491
      case VK_Y:
1492
      case VK_Z:
1493
      case VK_OPEN_BRACKET:
1494
      case VK_BACK_SLASH:
1495
      case VK_CLOSE_BRACKET:
1496
        return "" + (char) keyCode;
1497
      case VK_NUMPAD0:
1498
      case VK_NUMPAD1:
1499
      case VK_NUMPAD2:
1500
      case VK_NUMPAD3:
1501
      case VK_NUMPAD4:
1502
      case VK_NUMPAD5:
1503
      case VK_NUMPAD6:
1504
      case VK_NUMPAD7:
1505
      case VK_NUMPAD8:
1506
      case VK_NUMPAD9:
1507
        return "NumPad-" + (keyCode - VK_NUMPAD0);
1508
      case VK_F1:
1509
      case VK_F2:
1510
      case VK_F3:
1511
      case VK_F4:
1512
      case VK_F5:
1513
      case VK_F6:
1514
      case VK_F7:
1515
      case VK_F8:
1516
      case VK_F9:
1517
      case VK_F10:
1518
      case VK_F11:
1519
      case VK_F12:
1520
        return "F" + (keyCode - (VK_F1 - 1));
1521
      case VK_F13:
1522
      case VK_F14:
1523
      case VK_F15:
1524
      case VK_F16:
1525
      case VK_F17:
1526
      case VK_F18:
1527
      case VK_F19:
1528
      case VK_F20:
1529
      case VK_F21:
1530
      case VK_F22:
1531
      case VK_F23:
1532
      case VK_F24:
1533
        return "F" + (keyCode - (VK_F13 - 13));
1534
      default:
1535
        // This is funky on negative numbers, but that's Sun's fault.
1536
        return "Unknown keyCode: 0x" + (keyCode < 0 ? "-" : "")
1537
          + Integer.toHexString(Math.abs(keyCode));
1538
      }
1539
  }
1540
 
1541
  /**
1542
   * Returns a string describing the modifiers, such as "Shift" or
1543
   * "Ctrl+Button1".
1544
   *
1545
   * XXX Sun claims this can be localized via the awt.properties file - how
1546
   * do we implement that?
1547
   *
1548
   * @param modifiers the old-style modifiers to convert to text
1549
   * @return a string representation of the modifiers in this bitmask
1550
   */
1551
  public static String getKeyModifiersText(int modifiers)
1552
  {
1553
    return getModifiersExText(EventModifier.extend(modifiers
1554
                                                   & EventModifier.OLD_MASK));
1555
  }
1556
 
1557
  /**
1558
   * Tests whether or not this key is an action key. An action key typically
1559
   * does not fire a KEY_TYPED event, and is not a modifier.
1560
   *
1561
   * @return true if this is an action key
1562
   */
1563
  public boolean isActionKey()
1564
  {
1565
    switch (keyCode)
1566
      {
1567
      case VK_PAUSE:
1568
      case VK_CAPS_LOCK:
1569
      case VK_KANA:
1570
      case VK_FINAL:
1571
      case VK_KANJI:
1572
      case VK_CONVERT:
1573
      case VK_NONCONVERT:
1574
      case VK_ACCEPT:
1575
      case VK_MODECHANGE:
1576
      case VK_PAGE_UP:
1577
      case VK_PAGE_DOWN:
1578
      case VK_END:
1579
      case VK_HOME:
1580
      case VK_LEFT:
1581
      case VK_UP:
1582
      case VK_RIGHT:
1583
      case VK_DOWN:
1584
      case VK_F1:
1585
      case VK_F2:
1586
      case VK_F3:
1587
      case VK_F4:
1588
      case VK_F5:
1589
      case VK_F6:
1590
      case VK_F7:
1591
      case VK_F8:
1592
      case VK_F9:
1593
      case VK_F10:
1594
      case VK_F11:
1595
      case VK_F12:
1596
      case VK_NUM_LOCK:
1597
      case VK_SCROLL_LOCK:
1598
      case VK_PRINTSCREEN:
1599
      case VK_INSERT:
1600
      case VK_HELP:
1601
      case VK_KP_UP:
1602
      case VK_KP_DOWN:
1603
      case VK_KP_LEFT:
1604
      case VK_KP_RIGHT:
1605
      case VK_ALPHANUMERIC:
1606
      case VK_KATAKANA:
1607
      case VK_HIRAGANA:
1608
      case VK_FULL_WIDTH:
1609
      case VK_HALF_WIDTH:
1610
      case VK_ROMAN_CHARACTERS:
1611
      case VK_ALL_CANDIDATES:
1612
      case VK_PREVIOUS_CANDIDATE:
1613
      case VK_CODE_INPUT:
1614
      case VK_JAPANESE_KATAKANA:
1615
      case VK_JAPANESE_HIRAGANA:
1616
      case VK_JAPANESE_ROMAN:
1617
      case VK_KANA_LOCK:
1618
      case VK_INPUT_METHOD_ON_OFF:
1619
      case VK_F13:
1620
      case VK_F14:
1621
      case VK_F15:
1622
      case VK_F16:
1623
      case VK_F17:
1624
      case VK_F18:
1625
      case VK_F19:
1626
      case VK_F20:
1627
      case VK_F21:
1628
      case VK_F22:
1629
      case VK_F23:
1630
      case VK_F24:
1631
      case VK_STOP:
1632
      case VK_AGAIN:
1633
      case VK_PROPS:
1634
      case VK_UNDO:
1635
      case VK_COPY:
1636
      case VK_PASTE:
1637
      case VK_FIND:
1638
      case VK_CUT:
1639
        return true;
1640
      default:
1641
        return false;
1642
      }
1643
  }
1644
 
1645
  /**
1646
   * Returns a string identifying the event.  This is formatted as the
1647
   * field name of the id type, followed by the keyCode, then the
1648
   * keyChar, modifiers (if any), extModifiers (if any), and
1649
   * keyLocation.
1650
   *
1651
   * @return a string identifying the event
1652
   */
1653
  public String paramString()
1654
  {
1655
    StringBuffer s = new StringBuffer();
1656
 
1657
    switch (id)
1658
      {
1659
      case KEY_PRESSED:
1660
        s.append("KEY_PRESSED");
1661
        break;
1662
      case KEY_RELEASED:
1663
        s.append("KEY_RELEASED");
1664
        break;
1665
      case KEY_TYPED:
1666
        s.append("KEY_TYPED");
1667
        break;
1668
      default:
1669
        s.append("unknown type");
1670
      }
1671
 
1672
    s.append(",keyCode=").append(keyCode);
1673
 
1674
    s.append(",keyText=").append(getKeyText(keyCode));
1675
 
1676
    s.append(",keyChar=");
1677
    if (isActionKey()
1678
        || keyCode == VK_SHIFT
1679
        || keyCode == VK_CONTROL
1680
        || keyCode == VK_ALT)
1681
      s.append("Undefined keyChar");
1682
    else
1683
      {
1684
        /* This output string must be selected by examining keyChar
1685
         * rather than keyCode, because key code information is not
1686
         * included in KEY_TYPED events.
1687
         */
1688
        if (keyChar == VK_BACK_SPACE
1689
            || keyChar == VK_TAB
1690
            || keyChar == VK_ENTER
1691
            || keyChar == VK_ESCAPE
1692
            || keyChar == VK_DELETE)
1693
          s.append(getKeyText(keyChar));
1694
        else
1695
          s.append("'").append(keyChar).append("'");
1696
      }
1697
 
1698
    if ((modifiers & CONVERT_MASK) != 0)
1699
      s.append(",modifiers=").append(getModifiersExText(modifiers
1700
                                                        & CONVERT_MASK));
1701
    if (modifiers != 0)
1702
      s.append(",extModifiers=").append(getModifiersExText(modifiers));
1703
 
1704
    s.append(",keyLocation=KEY_LOCATION_");
1705
    switch (keyLocation)
1706
      {
1707
      case KEY_LOCATION_UNKNOWN:
1708
        s.append("UNKNOWN");
1709
        break;
1710
      case KEY_LOCATION_STANDARD:
1711
        s.append("STANDARD");
1712
        break;
1713
      case KEY_LOCATION_LEFT:
1714
        s.append("LEFT");
1715
        break;
1716
      case KEY_LOCATION_RIGHT:
1717
        s.append("RIGHT");
1718
        break;
1719
      case KEY_LOCATION_NUMPAD:
1720
        s.append("NUMPAD");
1721
      }
1722
 
1723
    return s.toString();
1724
  }
1725
 
1726
  /**
1727
   * Reads in the object from a serial stream.
1728
   *
1729
   * @param s the stream to read from
1730
   * @throws IOException if deserialization fails
1731
   * @throws ClassNotFoundException if deserialization fails
1732
   * @serialData default, except that the modifiers are converted to new style
1733
   */
1734
  private void readObject(ObjectInputStream s)
1735
    throws IOException, ClassNotFoundException
1736
  {
1737
    s.defaultReadObject();
1738
    modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK;
1739
  }
1740
} // class KeyEvent

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.