libjava/ChangeLog:
[official-gcc.git] / libjava / classpath / java / awt / event / KeyEvent.java
blobbb7ed4c2dc74a626cbd9fc987d18c3dffe486a95
1 /* KeyEvent.java -- event for key presses
2 Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package java.awt.event;
41 import gnu.java.awt.EventModifier;
42 import gnu.java.lang.CPStringBuilder;
44 import java.awt.Component;
45 import java.io.IOException;
46 import java.io.ObjectInputStream;
48 /**
49 * This event is generated when a key is pressed or released. There are two
50 * categories of key events:
52 * <p><em>"Key typed" events</em> are higher-level, and have already
53 * compensated for modifiers and keyboard layout to generate a single Unicode
54 * character. It may take several key press events to generate one key typed.
55 * The <code>getKeyCode</code> method will return <code>VK_UNDEFINED</code>,
56 * and <code>getKeyChar</code> will return a valid Unicode character or
57 * <code>CHAR_UNDEFINED</code>.
59 * <p><em>"Key pressed" and "key released" events</em> are lower-level, and
60 * are platform and keyboard dependent. They correspond to the actaul motion
61 * on a keyboard, and return a virtual key code which labels the key that was
62 * pressed. The <code>getKeyCode</code> method will return one of the
63 * <code>VK_*</code> constants (except VK_UNDEFINED), and the
64 * <code>getKeyChar</code> method is undefined.
66 * <p>Some keys do not generate key typed events, such as the F1 or HELP keys.
67 * Not all keyboards can generate all virtual keys, and no attempt is made to
68 * simulate the ones that can't be typed. Virtual keys correspond to the
69 * keyboard layout, so for example, VK_Q in English is VK_A in French. Also,
70 * there are some additional virtual keys to ease handling of actions, such
71 * as VK_ALL_CANDIDATES in place of ALT+VK_CONVERT. Do not rely on the value
72 * of the VK_* constants, except for VK_ENTER, VK_BACK_SPACE, and VK_TAB.
74 * @author Aaron M. Renn (arenn@urbanophile.com)
75 * @author Eric Blake (ebb9@email.byu.edu)
76 * @see KeyAdapter
77 * @see KeyListener
78 * @since 1.1
79 * @status updated to 1.4
81 public class KeyEvent extends InputEvent
83 /**
84 * Compatible with JDK 1.1+.
86 private static final long serialVersionUID = -2352130953028126954L;
88 /** This is the first id in the range of event ids used by this class. */
89 public static final int KEY_FIRST = 400;
91 /** This is the last id in the range of event ids used by this class. */
92 public static final int KEY_LAST = 402;
94 /**
95 * This event id indicates a key was typed, which is a key press followed
96 * by a key release to generate an actual Unicode character. It may take
97 * several key presses to generate one key typed event, and some action
98 * keys have no corresponding key typed.
100 public static final int KEY_TYPED = 400;
102 /** This event id indicates a key was pressed. */
103 public static final int KEY_PRESSED = 401;
105 /** This event it indicates a key was released. */
106 public static final int KEY_RELEASED = 402;
108 /** The virtual key Enter, which will always map to '\n'. */
109 public static final int VK_ENTER = '\n';
111 /** The virtual key Backspace, which will always map to '\b'. */
112 public static final int VK_BACK_SPACE = '\b';
114 /** The virtual key Tab, which will always map to '\t'. */
115 public static final int VK_TAB = '\t';
117 /** The virtual key Cancel. */
118 public static final int VK_CANCEL = 3;
120 /** The virtual key VK_CLEAR. */
121 public static final int VK_CLEAR = 12;
123 /** The virtual key VK_SHIFT. */
124 public static final int VK_SHIFT = 16;
126 /** The virtual key VK_CONTROL. */
127 public static final int VK_CONTROL = 17;
129 /** The virtual key VK_ALT. */
130 public static final int VK_ALT = 18;
132 /** The virtual key VK_PAUSE. */
133 public static final int VK_PAUSE = 19;
135 /** The virtual key VK_CAPS_LOCK. */
136 public static final int VK_CAPS_LOCK = 20;
138 /** The virtual key VK_ESCAPE. */
139 public static final int VK_ESCAPE = 27;
141 /** The virtual key VK_SPACE. */
142 public static final int VK_SPACE = ' ';
144 /** The virtual key VK_PAGE_UP. */
145 public static final int VK_PAGE_UP = 33;
147 /** The virtual key VK_PAGE_DOWN. */
148 public static final int VK_PAGE_DOWN = 34;
150 /** The virtual key VK_END. */
151 public static final int VK_END = 35;
153 /** The virtual key VK_HOME. */
154 public static final int VK_HOME = 36;
157 * The virtual key for the non-numpad VK_LEFT.
159 * @see #VK_KP_LEFT
161 public static final int VK_LEFT = 37;
164 * The virtual key for the non-numpad VK_UP.
166 * @see #VK_KP_UP
168 public static final int VK_UP = 38;
171 * The virtual key for the non-numpad VK_RIGHT.
173 * @see #VK_KP_RIGHT
175 public static final int VK_RIGHT = 39;
178 * The virtual key for the non-numpad VK_DOWN.
180 * @see #VK_KP_DOWN
182 public static final int VK_DOWN = 40;
184 /** The virtual key VK_COMMA. */
185 public static final int VK_COMMA = ',';
188 * The virtual key VK_MINUS.
190 * @since 1.2
192 public static final int VK_MINUS = '-';
194 /** The virtual key VK_PERIOD. */
195 public static final int VK_PERIOD = '.';
197 /** The virtual key VK_SLASH. */
198 public static final int VK_SLASH = '/';
200 /** The virtual key VK_0. */
201 public static final int VK_0 = '0';
203 /** The virtual key VK_1. */
204 public static final int VK_1 = '1';
206 /** The virtual key VK_2. */
207 public static final int VK_2 = '2';
209 /** The virtual key VK_3. */
210 public static final int VK_3 = '3';
212 /** The virtual key VK_4. */
213 public static final int VK_4 = '4';
215 /** The virtual key VK_5. */
216 public static final int VK_5 = '5';
218 /** The virtual key VK_6. */
219 public static final int VK_6 = '6';
221 /** The virtual key VK_7. */
222 public static final int VK_7 = '7';
224 /** The virtual key VK_8. */
225 public static final int VK_8 = '8';
227 /** The virtual key VK_9. */
228 public static final int VK_9 = '9';
230 /** The virtual key VK_SEMICOLON. */
231 public static final int VK_SEMICOLON = ';';
233 /** The virtual key VK_EQUALS. */
234 public static final int VK_EQUALS = '=';
236 /** The virtual key VK_A. */
237 public static final int VK_A = 'A';
239 /** The virtual key VK_B. */
240 public static final int VK_B = 'B';
242 /** The virtual key VK_C. */
243 public static final int VK_C = 'C';
245 /** The virtual key VK_D. */
246 public static final int VK_D = 'D';
248 /** The virtual key VK_E. */
249 public static final int VK_E = 'E';
251 /** The virtual key VK_F. */
252 public static final int VK_F = 'F';
254 /** The virtual key VK_G. */
255 public static final int VK_G = 'G';
257 /** The virtual key VK_H. */
258 public static final int VK_H = 'H';
260 /** The virtual key VK_I. */
261 public static final int VK_I = 'I';
263 /** The virtual key VK_J. */
264 public static final int VK_J = 'J';
266 /** The virtual key VK_K. */
267 public static final int VK_K = 'K';
269 /** The virtual key VK_L. */
270 public static final int VK_L = 'L';
272 /** The virtual key VK_M. */
273 public static final int VK_M = 'M';
275 /** The virtual key VK_N. */
276 public static final int VK_N = 'N';
278 /** The virtual key VK_O. */
279 public static final int VK_O = 'O';
281 /** The virtual key VK_P. */
282 public static final int VK_P = 'P';
284 /** The virtual key VK_Q. */
285 public static final int VK_Q = 'Q';
287 /** The virtual key VK_R. */
288 public static final int VK_R = 'R';
290 /** The virtual key VK_S. */
291 public static final int VK_S = 'S';
293 /** The virtual key VK_T. */
294 public static final int VK_T = 'T';
296 /** The virtual key VK_U. */
297 public static final int VK_U = 'U';
299 /** The virtual key VK_V. */
300 public static final int VK_V = 'V';
302 /** The virtual key VK_W. */
303 public static final int VK_W = 'W';
305 /** The virtual key VK_X. */
306 public static final int VK_X = 'X';
308 /** The virtual key VK_Y. */
309 public static final int VK_Y = 'Y';
311 /** The virtual key VK_Z. */
312 public static final int VK_Z = 'Z';
314 /** The virtual key VK_OPEN_BRACKET. */
315 public static final int VK_OPEN_BRACKET = '[';
317 /** The virtual key VK_BACK_SLASH. */
318 public static final int VK_BACK_SLASH = '\\';
320 /** The virtual key VK_CLOSE_BRACKET. */
321 public static final int VK_CLOSE_BRACKET = ']';
323 /** The virtual key VK_NUMPAD0. */
324 public static final int VK_NUMPAD0 = 96;
326 /** The virtual key VK_NUMPAD1. */
327 public static final int VK_NUMPAD1 = 97;
329 /** The virtual key VK_NUMPAD2. */
330 public static final int VK_NUMPAD2 = 98;
332 /** The virtual key VK_NUMPAD3. */
333 public static final int VK_NUMPAD3 = 99;
335 /** The virtual key VK_NUMPAD4. */
336 public static final int VK_NUMPAD4 = 100;
338 /** The virtual key VK_NUMPAD5. */
339 public static final int VK_NUMPAD5 = 101;
341 /** The virtual key VK_NUMPAD6. */
342 public static final int VK_NUMPAD6 = 102;
344 /** The virtual key VK_NUMPAD7. */
345 public static final int VK_NUMPAD7 = 103;
347 /** The virtual key VK_NUMPAD8. */
348 public static final int VK_NUMPAD8 = 104;
350 /** The virtual key VK_NUMPAD9. */
351 public static final int VK_NUMPAD9 = 105;
353 /** The virtual key VK_MULTIPLY. */
354 public static final int VK_MULTIPLY = 106;
356 /** The virtual key VK_ADD. */
357 public static final int VK_ADD = 107;
360 * The virtual key VK_SEPARATOR, handily mispelled for those who can't
361 * figure it out.
363 * @deprecated use {@link #VK_SEPARATOR}
365 public static final int VK_SEPARATER = 108;
368 * The virtual key VK_SEPARATOR.
370 * @since 1.4
372 public static final int VK_SEPARATOR = 108;
374 /** The virtual key VK_SUBTRACT. */
375 public static final int VK_SUBTRACT = 109;
377 /** The virtual key VK_DECIMAL. */
378 public static final int VK_DECIMAL = 110;
380 /** The virtual key VK_DIVIDE. */
381 public static final int VK_DIVIDE = 111;
383 /** The virtual key VK_DELETE. */
384 public static final int VK_DELETE = 127;
386 /** The virtual key VK_NUM_LOCK. */
387 public static final int VK_NUM_LOCK = 144;
389 /** The virtual key VK_SCROLL_LOCK. */
390 public static final int VK_SCROLL_LOCK = 145;
392 /** The virtual key VK_F1. */
393 public static final int VK_F1 = 112;
395 /** The virtual key VK_F2. */
396 public static final int VK_F2 = 113;
398 /** The virtual key VK_F3. */
399 public static final int VK_F3 = 114;
401 /** The virtual key VK_F4. */
402 public static final int VK_F4 = 115;
404 /** The virtual key VK_F5. */
405 public static final int VK_F5 = 116;
407 /** The virtual key VK_F6. */
408 public static final int VK_F6 = 117;
410 /** The virtual key VK_F7. */
411 public static final int VK_F7 = 118;
413 /** The virtual key VK_F8. */
414 public static final int VK_F8 = 119;
416 /** The virtual key VK_F9. */
417 public static final int VK_F9 = 120;
419 /** The virtual key VK_F10. */
420 public static final int VK_F10 = 121;
422 /** The virtual key VK_F11. */
423 public static final int VK_F11 = 122;
425 /** The virtual key VK_F12. */
426 public static final int VK_F12 = 123;
429 * The virtual key VK_F13.
431 * @since 1.2
433 public static final int VK_F13 = 61440;
436 * The virtual key VK_F14.
438 * @since 1.2
440 public static final int VK_F14 = 61441;
443 * The virtual key VK_F15.
445 * @since 1.2
447 public static final int VK_F15 = 61442;
450 * The virtual key VK_F16.
452 * @since 1.2
454 public static final int VK_F16 = 61443;
457 * The virtual key VK_F17.
459 * @since 1.2
461 public static final int VK_F17 = 61444;
464 * The virtual key VK_F18.
466 * @since 1.2
468 public static final int VK_F18 = 61445;
471 * The virtual key VK_F19.
473 * @since 1.2
475 public static final int VK_F19 = 61446;
478 * The virtual key VK_F20.
480 * @since 1.2
482 public static final int VK_F20 = 61447;
485 * The virtual key VK_F21.
487 * @since 1.2
489 public static final int VK_F21 = 61448;
492 * The virtual key VK_F22.
494 * @since 1.2
496 public static final int VK_F22 = 61449;
499 * The virtual key VK_F23.
501 * @since 1.2
503 public static final int VK_F23 = 61450;
506 * The virtual key VK_F24.
508 * @since 1.2
510 public static final int VK_F24 = 61451;
512 /** The virtual key VK_PRINTSCREEN. */
513 public static final int VK_PRINTSCREEN = 154;
515 /** The virtual key VK_INSERT. */
516 public static final int VK_INSERT = 155;
518 /** The virtual key VK_HELP. */
519 public static final int VK_HELP = 156;
521 /** The virtual key VK_META. */
522 public static final int VK_META = 157;
524 /** The virtual key VK_BACK_QUOTE. */
525 public static final int VK_BACK_QUOTE = 192;
527 /** The virtual key VK_QUOTE. */
528 public static final int VK_QUOTE = 222;
531 * The virtual key for the numpad VK_KP_UP.
533 * @see #VK_UP
534 * @since 1.2
536 public static final int VK_KP_UP = 224;
539 * The virtual key for the numpad VK_KP_DOWN.
541 * @see #VK_DOWN
542 * @since 1.2
544 public static final int VK_KP_DOWN = 225;
547 * The virtual key for the numpad VK_KP_LEFT.
549 * @see #VK_LEFT
550 * @since 1.2
552 public static final int VK_KP_LEFT = 226;
555 * The virtual key for the numpad VK_KP_RIGHT.
557 * @see #VK_RIGHT
558 * @since 1.2
560 public static final int VK_KP_RIGHT = 227;
563 * The virtual key VK_DEAD_GRAVE.
565 * @since 1.2
567 public static final int VK_DEAD_GRAVE = 128;
570 * The virtual key VK_DEAD_ACUTE.
572 * @since 1.2
574 public static final int VK_DEAD_ACUTE = 129;
577 * The virtual key VK_DEAD_CIRCUMFLEX.
579 * @since 1.2
581 public static final int VK_DEAD_CIRCUMFLEX = 130;
584 * The virtual key VK_DEAD_TILDE.
586 * @since 1.2
588 public static final int VK_DEAD_TILDE = 131;
591 * The virtual key VK_DEAD_MACRON.
593 * @since 1.2
595 public static final int VK_DEAD_MACRON = 132;
598 * The virtual key VK_DEAD_BREVE.
600 * @since 1.2
602 public static final int VK_DEAD_BREVE = 133;
605 * The virtual key VK_DEAD_ABOVEDOT.
607 * @since 1.2
609 public static final int VK_DEAD_ABOVEDOT = 134;
612 * The virtual key VK_DEAD_DIAERESIS.
614 * @since 1.2
616 public static final int VK_DEAD_DIAERESIS = 135;
619 * The virtual key VK_DEAD_ABOVERING.
621 * @since 1.2
623 public static final int VK_DEAD_ABOVERING = 136;
626 * The virtual key VK_DEAD_DOUBLEACUTE.
628 * @since 1.2
630 public static final int VK_DEAD_DOUBLEACUTE = 137;
633 * The virtual key VK_DEAD_CARON.
635 * @since 1.2
637 public static final int VK_DEAD_CARON = 138;
640 * The virtual key VK_DEAD_CEDILLA.
642 * @since 1.2
644 public static final int VK_DEAD_CEDILLA = 139;
647 * The virtual key VK_DEAD_OGONEK.
649 * @since 1.2
651 public static final int VK_DEAD_OGONEK = 140;
654 * The virtual key VK_DEAD_IOTA.
656 * @since 1.2
658 public static final int VK_DEAD_IOTA = 141;
661 * The virtual key VK_DEAD_VOICED_SOUND.
663 * @since 1.2
665 public static final int VK_DEAD_VOICED_SOUND = 142;
668 * The virtual key VK_DEAD_SEMIVOICED_SOUND.
670 * @since 1.2
672 public static final int VK_DEAD_SEMIVOICED_SOUND = 143;
675 * The virtual key VK_AMPERSAND.
677 * @since 1.2
679 public static final int VK_AMPERSAND = 150;
682 * The virtual key VK_ASTERISK.
684 * @since 1.2
686 public static final int VK_ASTERISK = 151;
689 * The virtual key VK_QUOTEDBL.
691 * @since 1.2
693 public static final int VK_QUOTEDBL = 152;
696 * The virtual key VK_LESS.
698 * @since 1.2
700 public static final int VK_LESS = 153;
703 * The virtual key VK_GREATER.
705 * @since 1.2
707 public static final int VK_GREATER = 160;
710 * The virtual key VK_BRACELEFT.
712 * @since 1.2
714 public static final int VK_BRACELEFT = 161;
717 * The virtual key VK_BRACERIGHT.
719 * @since 1.2
721 public static final int VK_BRACERIGHT = 162;
724 * The virtual key VK_AT.
726 * @since 1.2
728 public static final int VK_AT = 512;
731 * The virtual key VK_COLON.
733 * @since 1.2
735 public static final int VK_COLON = 513;
738 * The virtual key VK_CIRCUMFLEX.
740 * @since 1.2
742 public static final int VK_CIRCUMFLEX = 514;
745 * The virtual key VK_DOLLAR.
747 * @since 1.2
749 public static final int VK_DOLLAR = 515;
752 * The virtual key VK_EURO_SIGN.
754 * @since 1.2
756 public static final int VK_EURO_SIGN = 516;
759 * The virtual key VK_EXCLAMATION_MARK.
761 * @since 1.2
763 public static final int VK_EXCLAMATION_MARK = 517;
766 * The virtual key VK_INVERTED_EXCLAMATION_MARK.
768 * @since 1.2
770 public static final int VK_INVERTED_EXCLAMATION_MARK = 518;
773 * The virtual key VK_LEFT_PARENTHESIS.
775 * @since 1.2
777 public static final int VK_LEFT_PARENTHESIS = 519;
780 * The virtual key VK_NUMBER_SIGN.
782 * @since 1.2
784 public static final int VK_NUMBER_SIGN = 520;
787 * The virtual key VK_PLUS.
789 * @since 1.2
791 public static final int VK_PLUS = 521;
794 * The virtual key VK_RIGHT_PARENTHESIS.
796 * @since 1.2
798 public static final int VK_RIGHT_PARENTHESIS = 522;
801 * The virtual key VK_UNDERSCORE.
803 * @since 1.2
805 public static final int VK_UNDERSCORE = 523;
807 /** The virtual key VK_FINAL. */
808 public static final int VK_FINAL = 24;
810 /** The virtual key VK_CONVERT. */
811 public static final int VK_CONVERT = 28;
813 /** The virtual key VK_NONCONVERT. */
814 public static final int VK_NONCONVERT = 29;
816 /** The virtual key VK_ACCEPT. */
817 public static final int VK_ACCEPT = 30;
819 /** The virtual key VK_MODECHANGE. */
820 public static final int VK_MODECHANGE = 31;
822 /** The virtual key VK_KANA. */
823 public static final int VK_KANA = 21;
825 /** The virtual key VK_KANJI. */
826 public static final int VK_KANJI = 25;
829 * The virtual key VK_ALPHANUMERIC.
831 * @since 1.2
833 public static final int VK_ALPHANUMERIC = 240;
836 * The virtual key VK_KATAKANA.
838 * @since 1.2
840 public static final int VK_KATAKANA = 241;
843 * The virtual key VK_HIRAGANA.
845 * @since 1.2
847 public static final int VK_HIRAGANA = 242;
850 * The virtual key VK_FULL_WIDTH.
852 * @since 1.2
854 public static final int VK_FULL_WIDTH = 243;
857 * The virtual key VK_HALF_WIDTH.
859 * @since 1.2
861 public static final int VK_HALF_WIDTH = 244;
864 * The virtual key VK_ROMAN_CHARACTERS.
866 * @since 1.2
868 public static final int VK_ROMAN_CHARACTERS = 245;
871 * The virtual key VK_ALL_CANDIDATES.
873 * @since 1.2
875 public static final int VK_ALL_CANDIDATES = 256;
878 * The virtual key VK_PREVIOUS_CANDIDATE.
880 * @since 1.2
882 public static final int VK_PREVIOUS_CANDIDATE = 257;
885 * The virtual key VK_CODE_INPUT.
887 * @since 1.2
889 public static final int VK_CODE_INPUT = 258;
892 * The virtual key VK_JAPANESE_KATAKANA.
894 * @since 1.2
896 public static final int VK_JAPANESE_KATAKANA = 259;
899 * The virtual key VK_JAPANESE_HIRAGANA.
901 * @since 1.2
903 public static final int VK_JAPANESE_HIRAGANA = 260;
906 * The virtual key VK_JAPANESE_ROMAN.
908 * @since 1.2
910 public static final int VK_JAPANESE_ROMAN = 261;
913 * The virtual key VK_KANA_LOCK.
915 * @since 1.3
917 public static final int VK_KANA_LOCK = 262;
920 * The virtual key VK_INPUT_METHOD_ON_OFF.
922 * @since 1.3
924 public static final int VK_INPUT_METHOD_ON_OFF = 263;
927 * The virtual key VK_CUT.
929 * @since 1.2
931 public static final int VK_CUT = 65489;
934 * The virtual key VK_COPY.
936 * @since 1.2
938 public static final int VK_COPY = 65485;
941 * The virtual key VK_PASTE.
943 * @since 1.2
945 public static final int VK_PASTE = 65487;
948 * The virtual key VK_UNDO.
950 * @since 1.2
952 public static final int VK_UNDO = 65483;
955 * The virtual key VK_AGAIN.
957 * @since 1.2
959 public static final int VK_AGAIN = 65481;
962 * The virtual key VK_FIND.
964 * @since 1.2
966 public static final int VK_FIND = 65488;
969 * The virtual key VK_PROPS.
971 * @since 1.2
973 public static final int VK_PROPS = 65482;
976 * The virtual key VK_STOP.
978 * @since 1.2
980 public static final int VK_STOP = 65480;
983 * The virtual key VK_COMPOSE.
985 * @since 1.2
987 public static final int VK_COMPOSE = 65312;
990 * The virtual key VK_ALT_GRAPH.
992 * @since 1.2
994 public static final int VK_ALT_GRAPH = 65406;
997 * The 'begin' key VK_BEGIN
999 * @since 1.5
1001 public static final int VK_BEGIN = 65368;
1004 * The context-menu key VK_CONTEXT_MENU
1006 * @since 1.5
1008 public static final int VK_CONTEXT_MENU = 525;
1011 * The 'Windows' key VK_WINDOWS
1013 * @since 1.5
1015 public static final int VK_WINDOWS = 524;
1018 * The virtual key VK_UNDEFINED. This is used for key typed events, which
1019 * do not have a virtual key.
1021 public static final int VK_UNDEFINED = 0;
1024 * The only char with no valid Unicode interpretation. This is used for
1025 * key pressed and key released events which do not have a valid keyChar.
1027 public static final char CHAR_UNDEFINED = '\uffff';
1030 * Indicates unknown or irrelavent key location. This is also used for
1031 * key typed events, which do not need a location.
1033 * @since 1.4
1035 public static final int KEY_LOCATION_UNKNOWN = 0;
1038 * Indicates a standard key location, with no left/right variants and not
1039 * on the numeric pad.
1041 * @since 1.4
1043 public static final int KEY_LOCATION_STANDARD = 1;
1046 * Indicates the key is on the left side of the keyboard, such as the left
1047 * shift.
1049 * @since 1.4
1051 public static final int KEY_LOCATION_LEFT = 2;
1054 * Indicates the key is on the right side of the keyboard, such as the right
1055 * shift.
1057 * @since 1.4
1059 public static final int KEY_LOCATION_RIGHT = 3;
1062 * Indicates the key is on the numeric pad, such as the numpad 0.
1064 * @since 1.4
1066 public static final int KEY_LOCATION_NUMPAD = 4;
1069 * The code assigned to the physical keyboard location (as adjusted by the
1070 * keyboard layout). Use the symbolic VK_* names instead of numbers.
1072 * @see #getKeyCode()
1073 * @serial the VK_ code for this key
1075 private int keyCode;
1078 * The Unicode character produced by the key type event. This has no meaning
1079 * for key pressed and key released events.
1081 * @see #getKeyChar()
1082 * @serial the Unicode value for this key
1084 private char keyChar;
1087 * The keyboard location of the key. One of {@link #KEY_LOCATION_UNKNOWN},
1088 * {@link #KEY_LOCATION_STANDARD}, {@link #KEY_LOCATION_LEFT},
1089 * {@link #KEY_LOCATION_RIGHT}, or {@link #KEY_LOCATION_NUMPAD}.
1091 * @see #getKeyLocation()
1092 * @serial the key location
1093 * @since 1.4
1095 private final int keyLocation;
1098 * Stores the state of the native event dispatching system, to correctly
1099 * dispatch in Component#dispatchEventImpl when a proxy is active.
1101 * XXX Does this matter in Classpath?
1103 * @serial whether the proxy is active
1105 private boolean isProxyActive;
1109 * Initializes a new instance of <code>KeyEvent</code> with the specified
1110 * information. Note that an invalid id leads to unspecified results.
1112 * @param source the component that generated this event
1113 * @param id the event id
1114 * @param when the timestamp when the even occurred
1115 * @param modifiers the modifier keys during the event, in old or new style
1116 * @param keyCode the integer constant for the virtual key type
1117 * @param keyChar the Unicode value of the key
1118 * @param keyLocation the location of the key
1119 * @throws IllegalArgumentException if source is null, if keyLocation is
1120 * invalid, or if (id == KEY_TYPED && (keyCode != VK_UNDEFINED
1121 * || keyChar == CHAR_UNDEFINED))
1123 public KeyEvent(Component source, int id, long when, int modifiers,
1124 int keyCode, char keyChar, int keyLocation)
1126 super(source, id, when, modifiers);
1127 this.keyCode = keyCode;
1128 this.keyChar = keyChar;
1129 this.keyLocation = keyLocation;
1130 if ((id == KEY_TYPED && (keyCode != VK_UNDEFINED
1131 || keyChar == CHAR_UNDEFINED))
1132 || keyLocation < KEY_LOCATION_UNKNOWN
1133 || keyLocation > KEY_LOCATION_NUMPAD)
1134 throw new IllegalArgumentException();
1138 * Initializes a new instance of <code>KeyEvent</code> with the specified
1139 * information. Note that an invalid id leads to unspecified results.
1141 * @param source the component that generated this event
1142 * @param id the event id
1143 * @param when the timestamp when the even occurred
1144 * @param modifiers the modifier keys during the event, in old or new style
1145 * @param keyCode the integer constant for the virtual key type
1146 * @param keyChar the Unicode value of the key
1147 * @throws IllegalArgumentException if source is null, or if
1148 * (id == KEY_TYPED && (keyCode != VK_UNDEFINED
1149 * || keyChar == CHAR_UNDEFINED))
1151 public KeyEvent(Component source, int id, long when, int modifiers,
1152 int keyCode, char keyChar)
1154 this(source, id, when, modifiers, keyCode, keyChar, KEY_LOCATION_UNKNOWN);
1158 * Initializes a new instance of <code>KeyEvent</code> with the specified
1159 * information. Note that an invalid id leads to unspecified results.
1161 * @param source the component that generated this event
1162 * @param id the event id
1163 * @param when the timestamp when the even occurred
1164 * @param modifiers the modifier keys during the event, in old or new style
1165 * @param keyCode the integer constant for the virtual key type
1166 * @throws IllegalArgumentException if source is null, or if
1167 * id == KEY_TYPED but keyCode != VK_UNDEFINED
1169 * @deprecated
1171 public KeyEvent(Component source, int id, long when, int modifiers,
1172 int keyCode)
1174 this(source, id, when, modifiers, keyCode, '\0', KEY_LOCATION_UNKNOWN);
1178 * Returns the key code for the event key. This will be one of the
1179 * <code>VK_*</code> constants defined in this class. If the event type is
1180 * KEY_TYPED, the result will be VK_UNDEFINED.
1182 * @return the key code for this event
1184 public int getKeyCode()
1186 return keyCode;
1190 * Sets the key code for this event. This must be one of the
1191 * <code>VK_*</code> constants defined in this class.
1193 * @param keyCode the new key code for this event
1195 public void setKeyCode(int keyCode)
1197 this.keyCode = keyCode;
1201 * Returns the Unicode value for the event key. This will be
1202 * <code>CHAR_UNDEFINED</code> if there is no Unicode equivalent for
1203 * this key, usually when this is a KEY_PRESSED or KEY_RELEASED event.
1205 * @return the Unicode character for this event
1207 public char getKeyChar()
1209 return keyChar;
1213 * Sets the Unicode character for this event to the specified value.
1215 * @param keyChar the new Unicode character for this event
1217 public void setKeyChar(char keyChar)
1219 this.keyChar = keyChar;
1223 * Sets the modifier keys to the specified value. This should be a union
1224 * of the bit mask constants from <code>InputEvent</code>. The use of this
1225 * method is not recommended, particularly for KEY_TYPED events, which do
1226 * not check if the modifiers were changed.
1228 * @param modifiers the new modifier value, in either old or new style
1229 * @see InputEvent
1231 * @deprecated
1233 public void setModifiers(int modifiers)
1235 this.modifiers = EventModifier.extend(modifiers);
1239 * Returns the keyboard location of the key that generated this event. This
1240 * provides a way to distinguish between keys like left and right shift
1241 * which share a common key code. The result will be one of
1242 * {@link #KEY_LOCATION_UNKNOWN}, {@link #KEY_LOCATION_STANDARD},
1243 * {@link #KEY_LOCATION_LEFT}, {@link #KEY_LOCATION_RIGHT}, or
1244 * {@link #KEY_LOCATION_NUMPAD}.
1246 * @return the key location
1247 * @since 1.4
1249 public int getKeyLocation()
1251 return keyLocation;
1255 * Returns the text name of key code, such as "HOME", "F1", or "A".
1257 * XXX Sun claims this can be localized via the awt.properties file - how
1258 * do we implement that?
1260 * @return the text name of the key code
1262 public static String getKeyText(int keyCode)
1264 switch (keyCode)
1266 case VK_CANCEL:
1267 return "Cancel";
1268 case VK_BACK_SPACE:
1269 return "Backspace";
1270 case VK_TAB:
1271 return "Tab";
1272 case VK_ENTER:
1273 return "Enter";
1274 case VK_CLEAR:
1275 return "Clear";
1276 case VK_SHIFT:
1277 return "Shift";
1278 case VK_CONTROL:
1279 return "Ctrl";
1280 case VK_ALT:
1281 return "Alt";
1282 case VK_PAUSE:
1283 return "Pause";
1284 case VK_CAPS_LOCK:
1285 return "Caps Lock";
1286 case VK_KANA:
1287 return "Kana";
1288 case VK_FINAL:
1289 return "Final";
1290 case VK_KANJI:
1291 return "Kanji";
1292 case VK_ESCAPE:
1293 return "Escape";
1294 case VK_CONVERT:
1295 return "Convert";
1296 case VK_NONCONVERT:
1297 return "No Convert";
1298 case VK_ACCEPT:
1299 return "Accept";
1300 case VK_MODECHANGE:
1301 return "Mode Change";
1302 case VK_SPACE:
1303 return "Space";
1304 case VK_PAGE_UP:
1305 return "Page Up";
1306 case VK_PAGE_DOWN:
1307 return "Page Down";
1308 case VK_END:
1309 return "End";
1310 case VK_HOME:
1311 return "Home";
1312 case VK_LEFT:
1313 case VK_KP_LEFT:
1314 return "Left";
1315 case VK_UP:
1316 case VK_KP_UP:
1317 return "Up";
1318 case VK_RIGHT:
1319 case VK_KP_RIGHT:
1320 return "Right";
1321 case VK_DOWN:
1322 case VK_KP_DOWN:
1323 return "Down";
1324 case VK_MINUS:
1325 return "Minus";
1326 case VK_MULTIPLY:
1327 return "NumPad *";
1328 case VK_ADD:
1329 return "NumPad +";
1330 case VK_SEPARATOR:
1331 return "NumPad ,";
1332 case VK_SUBTRACT:
1333 return "NumPad -";
1334 case VK_DECIMAL:
1335 return "NumPad .";
1336 case VK_DIVIDE:
1337 return "NumPad /";
1338 case VK_DELETE:
1339 return "Delete";
1340 case VK_DEAD_GRAVE:
1341 return "Dead Grave";
1342 case VK_DEAD_ACUTE:
1343 return "Dead Acute";
1344 case VK_DEAD_CIRCUMFLEX:
1345 return "Dead Circumflex";
1346 case VK_DEAD_TILDE:
1347 return "Dead Tilde";
1348 case VK_DEAD_MACRON:
1349 return "Dead Macron";
1350 case VK_DEAD_BREVE:
1351 return "Dead Breve";
1352 case VK_DEAD_ABOVEDOT:
1353 return "Dead Above Dot";
1354 case VK_DEAD_DIAERESIS:
1355 return "Dead Diaeresis";
1356 case VK_DEAD_ABOVERING:
1357 return "Dead Above Ring";
1358 case VK_DEAD_DOUBLEACUTE:
1359 return "Dead Double Acute";
1360 case VK_DEAD_CARON:
1361 return "Dead Caron";
1362 case VK_DEAD_CEDILLA:
1363 return "Dead Cedilla";
1364 case VK_DEAD_OGONEK:
1365 return "Dead Ogonek";
1366 case VK_DEAD_IOTA:
1367 return "Dead Iota";
1368 case VK_DEAD_VOICED_SOUND:
1369 return "Dead Voiced Sound";
1370 case VK_DEAD_SEMIVOICED_SOUND:
1371 return "Dead Semivoiced Sound";
1372 case VK_NUM_LOCK:
1373 return "Num Lock";
1374 case VK_SCROLL_LOCK:
1375 return "Scroll Lock";
1376 case VK_AMPERSAND:
1377 return "Ampersand";
1378 case VK_ASTERISK:
1379 return "Asterisk";
1380 case VK_QUOTEDBL:
1381 return "Double Quote";
1382 case VK_LESS:
1383 return "Less";
1384 case VK_PRINTSCREEN:
1385 return "Print Screen";
1386 case VK_INSERT:
1387 return "Insert";
1388 case VK_HELP:
1389 return "Help";
1390 case VK_META:
1391 return "Meta";
1392 case VK_GREATER:
1393 return "Greater";
1394 case VK_BRACELEFT:
1395 return "Left Brace";
1396 case VK_BRACERIGHT:
1397 return "Right Brace";
1398 case VK_BACK_QUOTE:
1399 return "Back Quote";
1400 case VK_QUOTE:
1401 return "Quote";
1402 case VK_ALPHANUMERIC:
1403 return "Alphanumeric";
1404 case VK_KATAKANA:
1405 return "Katakana";
1406 case VK_HIRAGANA:
1407 return "Hiragana";
1408 case VK_FULL_WIDTH:
1409 return "Full-Width";
1410 case VK_HALF_WIDTH:
1411 return "Half-Width";
1412 case VK_ROMAN_CHARACTERS:
1413 return "Roman Characters";
1414 case VK_ALL_CANDIDATES:
1415 return "All Candidates";
1416 case VK_PREVIOUS_CANDIDATE:
1417 return "Previous Candidate";
1418 case VK_CODE_INPUT:
1419 return "Code Input";
1420 case VK_JAPANESE_KATAKANA:
1421 return "Japanese Katakana";
1422 case VK_JAPANESE_HIRAGANA:
1423 return "Japanese Hiragana";
1424 case VK_JAPANESE_ROMAN:
1425 return "Japanese Roman";
1426 case VK_KANA_LOCK:
1427 return "Kana Lock";
1428 case VK_INPUT_METHOD_ON_OFF:
1429 return "Input Method On/Off";
1430 case VK_AT:
1431 return "At";
1432 case VK_COLON:
1433 return "Colon";
1434 case VK_CIRCUMFLEX:
1435 return "Circumflex";
1436 case VK_DOLLAR:
1437 return "Dollar";
1438 case VK_EURO_SIGN:
1439 return "Euro";
1440 case VK_EXCLAMATION_MARK:
1441 return "Exclamation Mark";
1442 case VK_INVERTED_EXCLAMATION_MARK:
1443 return "Inverted Exclamation Mark";
1444 case VK_LEFT_PARENTHESIS:
1445 return "Left Parenthesis";
1446 case VK_NUMBER_SIGN:
1447 return "Number Sign";
1448 case VK_PLUS:
1449 return "Plus";
1450 case VK_RIGHT_PARENTHESIS:
1451 return "Right Parenthesis";
1452 case VK_UNDERSCORE:
1453 return "Underscore";
1454 case VK_COMPOSE:
1455 return "Compose";
1456 case VK_ALT_GRAPH:
1457 return "Alt Graph";
1458 case VK_STOP:
1459 return "Stop";
1460 case VK_AGAIN:
1461 return "Again";
1462 case VK_PROPS:
1463 return "Props";
1464 case VK_UNDO:
1465 return "Undo";
1466 case VK_COPY:
1467 return "Copy";
1468 case VK_PASTE:
1469 return "Paste";
1470 case VK_FIND:
1471 return "Find";
1472 case VK_CUT:
1473 return "Cut";
1474 case VK_COMMA:
1475 case VK_PERIOD:
1476 case VK_SLASH:
1477 case VK_0:
1478 case VK_1:
1479 case VK_2:
1480 case VK_3:
1481 case VK_4:
1482 case VK_5:
1483 case VK_6:
1484 case VK_7:
1485 case VK_8:
1486 case VK_9:
1487 case VK_SEMICOLON:
1488 case VK_EQUALS:
1489 case VK_A:
1490 case VK_B:
1491 case VK_C:
1492 case VK_D:
1493 case VK_E:
1494 case VK_F:
1495 case VK_G:
1496 case VK_H:
1497 case VK_I:
1498 case VK_J:
1499 case VK_K:
1500 case VK_L:
1501 case VK_M:
1502 case VK_N:
1503 case VK_O:
1504 case VK_P:
1505 case VK_Q:
1506 case VK_R:
1507 case VK_S:
1508 case VK_T:
1509 case VK_U:
1510 case VK_V:
1511 case VK_W:
1512 case VK_X:
1513 case VK_Y:
1514 case VK_Z:
1515 case VK_OPEN_BRACKET:
1516 case VK_BACK_SLASH:
1517 case VK_CLOSE_BRACKET:
1518 return "" + (char) keyCode;
1519 case VK_NUMPAD0:
1520 case VK_NUMPAD1:
1521 case VK_NUMPAD2:
1522 case VK_NUMPAD3:
1523 case VK_NUMPAD4:
1524 case VK_NUMPAD5:
1525 case VK_NUMPAD6:
1526 case VK_NUMPAD7:
1527 case VK_NUMPAD8:
1528 case VK_NUMPAD9:
1529 return "NumPad-" + (keyCode - VK_NUMPAD0);
1530 case VK_F1:
1531 case VK_F2:
1532 case VK_F3:
1533 case VK_F4:
1534 case VK_F5:
1535 case VK_F6:
1536 case VK_F7:
1537 case VK_F8:
1538 case VK_F9:
1539 case VK_F10:
1540 case VK_F11:
1541 case VK_F12:
1542 return "F" + (keyCode - (VK_F1 - 1));
1543 case VK_F13:
1544 case VK_F14:
1545 case VK_F15:
1546 case VK_F16:
1547 case VK_F17:
1548 case VK_F18:
1549 case VK_F19:
1550 case VK_F20:
1551 case VK_F21:
1552 case VK_F22:
1553 case VK_F23:
1554 case VK_F24:
1555 return "F" + (keyCode - (VK_F13 - 13));
1556 default:
1557 // This is funky on negative numbers, but that's Sun's fault.
1558 return "Unknown keyCode: 0x" + (keyCode < 0 ? "-" : "")
1559 + Integer.toHexString(Math.abs(keyCode));
1564 * Returns a string describing the modifiers, such as "Shift" or
1565 * "Ctrl+Button1".
1567 * XXX Sun claims this can be localized via the awt.properties file - how
1568 * do we implement that?
1570 * @param modifiers the old-style modifiers to convert to text
1571 * @return a string representation of the modifiers in this bitmask
1573 public static String getKeyModifiersText(int modifiers)
1575 return getModifiersExText(EventModifier.extend(modifiers
1576 & EventModifier.OLD_MASK));
1580 * Tests whether or not this key is an action key. An action key typically
1581 * does not fire a KEY_TYPED event, and is not a modifier.
1583 * @return true if this is an action key
1585 public boolean isActionKey()
1587 switch (keyCode)
1589 case VK_PAUSE:
1590 case VK_CAPS_LOCK:
1591 case VK_KANA:
1592 case VK_FINAL:
1593 case VK_KANJI:
1594 case VK_CONVERT:
1595 case VK_NONCONVERT:
1596 case VK_ACCEPT:
1597 case VK_MODECHANGE:
1598 case VK_PAGE_UP:
1599 case VK_PAGE_DOWN:
1600 case VK_END:
1601 case VK_HOME:
1602 case VK_LEFT:
1603 case VK_UP:
1604 case VK_RIGHT:
1605 case VK_DOWN:
1606 case VK_F1:
1607 case VK_F2:
1608 case VK_F3:
1609 case VK_F4:
1610 case VK_F5:
1611 case VK_F6:
1612 case VK_F7:
1613 case VK_F8:
1614 case VK_F9:
1615 case VK_F10:
1616 case VK_F11:
1617 case VK_F12:
1618 case VK_NUM_LOCK:
1619 case VK_SCROLL_LOCK:
1620 case VK_PRINTSCREEN:
1621 case VK_INSERT:
1622 case VK_HELP:
1623 case VK_KP_UP:
1624 case VK_KP_DOWN:
1625 case VK_KP_LEFT:
1626 case VK_KP_RIGHT:
1627 case VK_ALPHANUMERIC:
1628 case VK_KATAKANA:
1629 case VK_HIRAGANA:
1630 case VK_FULL_WIDTH:
1631 case VK_HALF_WIDTH:
1632 case VK_ROMAN_CHARACTERS:
1633 case VK_ALL_CANDIDATES:
1634 case VK_PREVIOUS_CANDIDATE:
1635 case VK_CODE_INPUT:
1636 case VK_JAPANESE_KATAKANA:
1637 case VK_JAPANESE_HIRAGANA:
1638 case VK_JAPANESE_ROMAN:
1639 case VK_KANA_LOCK:
1640 case VK_INPUT_METHOD_ON_OFF:
1641 case VK_F13:
1642 case VK_F14:
1643 case VK_F15:
1644 case VK_F16:
1645 case VK_F17:
1646 case VK_F18:
1647 case VK_F19:
1648 case VK_F20:
1649 case VK_F21:
1650 case VK_F22:
1651 case VK_F23:
1652 case VK_F24:
1653 case VK_STOP:
1654 case VK_AGAIN:
1655 case VK_PROPS:
1656 case VK_UNDO:
1657 case VK_COPY:
1658 case VK_PASTE:
1659 case VK_FIND:
1660 case VK_CUT:
1661 return true;
1662 default:
1663 return false;
1668 * Returns a string identifying the event. This is formatted as the
1669 * field name of the id type, followed by the keyCode, then the
1670 * keyChar, modifiers (if any), extModifiers (if any), and
1671 * keyLocation.
1673 * @return a string identifying the event
1675 public String paramString()
1677 CPStringBuilder s = new CPStringBuilder();
1679 switch (id)
1681 case KEY_PRESSED:
1682 s.append("KEY_PRESSED");
1683 break;
1684 case KEY_RELEASED:
1685 s.append("KEY_RELEASED");
1686 break;
1687 case KEY_TYPED:
1688 s.append("KEY_TYPED");
1689 break;
1690 default:
1691 s.append("unknown type");
1694 s.append(",keyCode=").append(keyCode);
1696 s.append(",keyText=").append(getKeyText(keyCode));
1698 s.append(",keyChar=");
1699 if (isActionKey()
1700 || keyCode == VK_SHIFT
1701 || keyCode == VK_CONTROL
1702 || keyCode == VK_ALT)
1703 s.append("Undefined keyChar");
1704 else
1706 /* This output string must be selected by examining keyChar
1707 * rather than keyCode, because key code information is not
1708 * included in KEY_TYPED events.
1710 if (keyChar == VK_BACK_SPACE
1711 || keyChar == VK_TAB
1712 || keyChar == VK_ENTER
1713 || keyChar == VK_ESCAPE
1714 || keyChar == VK_DELETE)
1715 s.append(getKeyText(keyChar));
1716 else
1717 s.append("'").append(keyChar).append("'");
1720 if ((modifiers & CONVERT_MASK) != 0)
1721 s.append(",modifiers=").append(getModifiersExText(modifiers
1722 & CONVERT_MASK));
1723 if (modifiers != 0)
1724 s.append(",extModifiers=").append(getModifiersExText(modifiers));
1726 s.append(",keyLocation=KEY_LOCATION_");
1727 switch (keyLocation)
1729 case KEY_LOCATION_UNKNOWN:
1730 s.append("UNKNOWN");
1731 break;
1732 case KEY_LOCATION_STANDARD:
1733 s.append("STANDARD");
1734 break;
1735 case KEY_LOCATION_LEFT:
1736 s.append("LEFT");
1737 break;
1738 case KEY_LOCATION_RIGHT:
1739 s.append("RIGHT");
1740 break;
1741 case KEY_LOCATION_NUMPAD:
1742 s.append("NUMPAD");
1745 return s.toString();
1749 * Reads in the object from a serial stream.
1751 * @param s the stream to read from
1752 * @throws IOException if deserialization fails
1753 * @throws ClassNotFoundException if deserialization fails
1754 * @serialData default, except that the modifiers are converted to new style
1756 private void readObject(ObjectInputStream s)
1757 throws IOException, ClassNotFoundException
1759 s.defaultReadObject();
1760 modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK;
1762 } // class KeyEvent