source: trunk/gcc/libjava/java/awt/event/KeyEvent.java

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

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