KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > event > KeyEvent


1 /*
2  * @(#)KeyEvent.java 1.76 07/11/22
3  *
4  * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt.event;
9
10 import java.awt.Event JavaDoc;
11 import java.awt.Component JavaDoc;
12 import java.awt.GraphicsEnvironment JavaDoc;
13 import java.awt.Toolkit JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.ObjectInputStream JavaDoc;
16
17 /**
18  * An event which indicates that a keystroke occurred in a component.
19  * <p>
20  * This low-level event is generated by a component object (such as a text
21  * field) when a key is pressed, released, or typed.
22  * The event is passed to every <code>KeyListener</code>
23  * or <code>KeyAdapter</code> object which registered to receive such
24  * events using the component's <code>addKeyListener</code> method.
25  * (<code>KeyAdapter</code> objects implement the
26  * <code>KeyListener</code> interface.) Each such listener object
27  * gets this <code>KeyEvent</code> when the event occurs.
28  * <p>
29  * <em>"Key typed" events</em> are higher-level and generally do not depend on
30  * the platform or keyboard layout. They are generated when a Unicode character
31  * is entered, and are the preferred way to find out about character input.
32  * In the simplest case, a key typed event is produced by a single key press
33  * (e.g., 'a'). Often, however, characters are produced by series of key
34  * presses (e.g., 'shift' + 'a'), and the mapping from key pressed events to
35  * key typed events may be many-to-one or many-to-many. Key releases are not
36  * usually necessary to generate a key typed event, but there are some cases
37  * where the key typed event is not generated until a key is released (e.g.,
38  * entering ASCII sequences via the Alt-Numpad method in Windows).
39  * No key typed events are generated for keys that don't generate Unicode
40  * characters (e.g., action keys, modifier keys, etc.).
41  * <p>
42  * The getKeyChar method always returns a valid Unicode character or
43  * CHAR_UNDEFINED. Character input is reported by KEY_TYPED events:
44  * KEY_PRESSED and KEY_RELEASED events are not necessarily associated
45  * with character input. Therefore, the result of the getKeyChar method
46  * is guaranteed to be meaningful only for KEY_TYPED events.
47  * <p>
48  * For key pressed and key released events, the getKeyCode method returns
49  * the event's keyCode. For key typed events, the getKeyCode method
50  * always returns VK_UNDEFINED.
51  *
52  * <p>
53  * <em>"Key pressed" and "key released" events</em> are lower-level and depend
54  * on the platform and keyboard layout. They are generated whenever a key is
55  * pressed or released, and are the only way to find out about keys that don't
56  * generate character input (e.g., action keys, modifier keys, etc.). The key
57  * being pressed or released is indicated by the getKeyCode method, which returns
58  * a virtual key code.
59  *
60  * <p>
61  * <em>Virtual key codes</em> are used to report which keyboard key has
62  * been pressed, rather than a character generated by the combination
63  * of one or more keystrokes (such as "A", which comes from shift and "a").
64  *
65  * <p>
66  * For example, pressing the Shift key will cause a KEY_PRESSED event
67  * with a VK_SHIFT keyCode, while pressing the 'a' key will result in
68  * a VK_A keyCode. After the 'a' key is released, a KEY_RELEASED event
69  * will be fired with VK_A. Separately, a KEY_TYPED event with a keyChar
70  * value of 'A' is generated.
71  *
72  * <p>
73  * Notes:
74  * <ul>
75  * <li>Key combinations which do not result in Unicode characters, such as action
76  * keys like F1 and the HELP key, do not generate KEY_TYPED events.
77  * <li>Not all keyboards or systems are capable of generating all
78  * virtual key codes. No attempt is made in Java to generate these keys
79  * artificially.
80  * <li>Virtual key codes do not identify a physical key: they depend on the
81  * platform and keyboard layout. For example, the key that generates VK_Q
82  * when using a U.S. keyboard layout will generate VK_A when using a French
83  * keyboard layout.
84  * <li>Not all characters have a keycode associated with them. For example,
85  * there is no keycode for the question mark because there is no keyboard
86  * for which it appears on the primary layer.
87  * <li>In order to support the platform-independent handling of action keys,
88  * the Java platform uses a few additional virtual key constants for functions
89  * that would otherwise have to be recognized by interpreting virtual key codes
90  * and modifiers. For example, for Japanese Windows keyboards, VK_ALL_CANDIDATES
91  * is returned instead of VK_CONVERT with the ALT modifier.
92  * </ul>
93  *
94  * <p>
95  * WARNING: Aside from those keys that are defined by the Java language
96  * (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of the VK_
97  * constants. Sun reserves the right to change these values as needed
98  * to accomodate a wider range of keyboards in the future.
99  *
100  * @author Carl Quinn
101  * @author Amy Fowler
102  * @author Norbert Lindenberg
103  * @version 1.76 11/22/07
104  *
105  * @see KeyAdapter
106  * @see KeyListener
107  * @see <a HREF="http://java.sun.com/docs/books/tutorial/post1.0/ui/keylistener.html">Tutorial: Writing a Key Listener</a>
108  * @see <a HREF="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
109  *
110  * @since 1.1
111  */

112 public class KeyEvent extends InputEvent JavaDoc {
113
114     /**
115      * Stores the state of native event dispatching system
116      * - true, if when the event was created event proxying
117      * mechanism was active
118      * - false, if it was inactive
119      * Used in Component.dispatchEventImpl to correctly dispatch
120      * events when proxy is active
121      */

122     private boolean isProxyActive = false;
123
124     /**
125      * The first number in the range of ids used for key events.
126      */

127     public static final int KEY_FIRST = 400;
128
129     /**
130      * The last number in the range of ids used for key events.
131      */

132     public static final int KEY_LAST = 402;
133
134     /**
135      * The "key typed" event. This event is generated when a character is
136      * entered. In the simplest case, it is produced by a single key press.
137      * Often, however, characters are produced by series of key presses, and
138      * the mapping from key pressed events to key typed events may be
139      * many-to-one or many-to-many.
140      */

141     public static final int KEY_TYPED = KEY_FIRST;
142
143     /**
144      * The "key pressed" event. This event is generated when a key
145      * is pushed down.
146      */

147     public static final int KEY_PRESSED = 1 + KEY_FIRST; //Event.KEY_PRESS
148

149     /**
150      * The "key released" event. This event is generated when a key
151      * is let up.
152      */

153     public static final int KEY_RELEASED = 2 + KEY_FIRST; //Event.KEY_RELEASE
154

155     /* Virtual key codes. */
156
157     public static final int VK_ENTER = '\n';
158     public static final int VK_BACK_SPACE = '\b';
159     public static final int VK_TAB = '\t';
160     public static final int VK_CANCEL = 0x03;
161     public static final int VK_CLEAR = 0x0C;
162     public static final int VK_SHIFT = 0x10;
163     public static final int VK_CONTROL = 0x11;
164     public static final int VK_ALT = 0x12;
165     public static final int VK_PAUSE = 0x13;
166     public static final int VK_CAPS_LOCK = 0x14;
167     public static final int VK_ESCAPE = 0x1B;
168     public static final int VK_SPACE = 0x20;
169     public static final int VK_PAGE_UP = 0x21;
170     public static final int VK_PAGE_DOWN = 0x22;
171     public static final int VK_END = 0x23;
172     public static final int VK_HOME = 0x24;
173
174     /**
175      * Constant for the non-numpad <b>left</b> arrow key.
176      * @see #VK_KP_LEFT
177      */

178     public static final int VK_LEFT = 0x25;
179
180     /**
181      * Constant for the non-numpad <b>up</b> arrow key.
182      * @see #VK_KP_UP
183      */

184     public static final int VK_UP = 0x26;
185
186     /**
187      * Constant for the non-numpad <b>right</b> arrow key.
188      * @see #VK_KP_RIGHT
189      */

190     public static final int VK_RIGHT = 0x27;
191
192     /**
193      * Constant for the non-numpad <b>down</b> arrow key.
194      * @see #VK_KP_DOWN
195      */

196     public static final int VK_DOWN = 0x28;
197
198     /**
199      * Constant for the comma key, ","
200      */

201     public static final int VK_COMMA = 0x2C;
202
203     /**
204      * Constant for the minus key, "-"
205      * @since 1.2
206      */

207     public static final int VK_MINUS = 0x2D;
208
209     /**
210      * Constant for the period key, "."
211      */

212     public static final int VK_PERIOD = 0x2E;
213
214     /**
215      * Constant for the forward slash key, "/"
216      */

217     public static final int VK_SLASH = 0x2F;
218
219     /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
220     public static final int VK_0 = 0x30;
221     public static final int VK_1 = 0x31;
222     public static final int VK_2 = 0x32;
223     public static final int VK_3 = 0x33;
224     public static final int VK_4 = 0x34;
225     public static final int VK_5 = 0x35;
226     public static final int VK_6 = 0x36;
227     public static final int VK_7 = 0x37;
228     public static final int VK_8 = 0x38;
229     public static final int VK_9 = 0x39;
230
231     /**
232      * Constant for the semicolon key, ";"
233      */

234     public static final int VK_SEMICOLON = 0x3B;
235
236     /**
237      * Constant for the equals key, "="
238      */

239     public static final int VK_EQUALS = 0x3D;
240
241     /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
242     public static final int VK_A = 0x41;
243     public static final int VK_B = 0x42;
244     public static final int VK_C = 0x43;
245     public static final int VK_D = 0x44;
246     public static final int VK_E = 0x45;
247     public static final int VK_F = 0x46;
248     public static final int VK_G = 0x47;
249     public static final int VK_H = 0x48;
250     public static final int VK_I = 0x49;
251     public static final int VK_J = 0x4A;
252     public static final int VK_K = 0x4B;
253     public static final int VK_L = 0x4C;
254     public static final int VK_M = 0x4D;
255     public static final int VK_N = 0x4E;
256     public static final int VK_O = 0x4F;
257     public static final int VK_P = 0x50;
258     public static final int VK_Q = 0x51;
259     public static final int VK_R = 0x52;
260     public static final int VK_S = 0x53;
261     public static final int VK_T = 0x54;
262     public static final int VK_U = 0x55;
263     public static final int VK_V = 0x56;
264     public static final int VK_W = 0x57;
265     public static final int VK_X = 0x58;
266     public static final int VK_Y = 0x59;
267     public static final int VK_Z = 0x5A;
268
269     /**
270      * Constant for the open bracket key, "["
271      */

272     public static final int VK_OPEN_BRACKET = 0x5B;
273
274     /**
275      * Constant for the back slash key, "\"
276      */

277     public static final int VK_BACK_SLASH = 0x5C;
278
279     /**
280      * Constant for the close bracket key, "]"
281      */

282     public static final int VK_CLOSE_BRACKET = 0x5D;
283
284     public static final int VK_NUMPAD0 = 0x60;
285     public static final int VK_NUMPAD1 = 0x61;
286     public static final int VK_NUMPAD2 = 0x62;
287     public static final int VK_NUMPAD3 = 0x63;
288     public static final int VK_NUMPAD4 = 0x64;
289     public static final int VK_NUMPAD5 = 0x65;
290     public static final int VK_NUMPAD6 = 0x66;
291     public static final int VK_NUMPAD7 = 0x67;
292     public static final int VK_NUMPAD8 = 0x68;
293     public static final int VK_NUMPAD9 = 0x69;
294     public static final int VK_MULTIPLY = 0x6A;
295     public static final int VK_ADD = 0x6B;
296
297     /**
298      * This constant is obsolete, and is included only for backwards
299      * compatibility.
300      * @see #VK_SEPARATOR
301      */

302     public static final int VK_SEPARATER = 0x6C;
303
304     /**
305      * Constant for the Numpad Separator key.
306      * @since 1.4
307      */

308     public static final int VK_SEPARATOR = VK_SEPARATER;
309
310     public static final int VK_SUBTRACT = 0x6D;
311     public static final int VK_DECIMAL = 0x6E;
312     public static final int VK_DIVIDE = 0x6F;
313     public static final int VK_DELETE = 0x7F; /* ASCII DEL */
314     public static final int VK_NUM_LOCK = 0x90;
315     public static final int VK_SCROLL_LOCK = 0x91;
316
317     /** Constant for the F1 function key. */
318     public static final int VK_F1 = 0x70;
319
320     /** Constant for the F2 function key. */
321     public static final int VK_F2 = 0x71;
322
323     /** Constant for the F3 function key. */
324     public static final int VK_F3 = 0x72;
325
326     /** Constant for the F4 function key. */
327     public static final int VK_F4 = 0x73;
328
329     /** Constant for the F5 function key. */
330     public static final int VK_F5 = 0x74;
331
332     /** Constant for the F6 function key. */
333     public static final int VK_F6 = 0x75;
334
335     /** Constant for the F7 function key. */
336     public static final int VK_F7 = 0x76;
337
338     /** Constant for the F8 function key. */
339     public static final int VK_F8 = 0x77;
340
341     /** Constant for the F9 function key. */
342     public static final int VK_F9 = 0x78;
343
344     /** Constant for the F10 function key. */
345     public static final int VK_F10 = 0x79;
346
347     /** Constant for the F11 function key. */
348     public static final int VK_F11 = 0x7A;
349
350     /** Constant for the F12 function key. */
351     public static final int VK_F12 = 0x7B;
352
353     /**
354      * Constant for the F13 function key.
355      * @since 1.2
356      */

357     /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */
358     public static final int VK_F13 = 0xF000;
359  
360     /**
361      * Constant for the F14 function key.
362      * @since 1.2
363      */

364     public static final int VK_F14 = 0xF001;
365  
366     /**
367      * Constant for the F15 function key.
368      * @since 1.2
369      */

370     public static final int VK_F15 = 0xF002;
371  
372     /**
373      * Constant for the F16 function key.
374      * @since 1.2
375      */

376     public static final int VK_F16 = 0xF003;
377  
378     /**
379      * Constant for the F17 function key.
380      * @since 1.2
381      */

382     public static final int VK_F17 = 0xF004;
383  
384     /**
385      * Constant for the F18 function key.
386      * @since 1.2
387      */

388     public static final int VK_F18 = 0xF005;
389  
390     /**
391      * Constant for the F19 function key.
392      * @since 1.2
393      */

394     public static final int VK_F19 = 0xF006;
395  
396     /**
397      * Constant for the F20 function key.
398      * @since 1.2
399      */

400     public static final int VK_F20 = 0xF007;
401  
402     /**
403      * Constant for the F21 function key.
404      * @since 1.2
405      */

406     public static final int VK_F21 = 0xF008;
407  
408     /**
409      * Constant for the F22 function key.
410      * @since 1.2
411      */

412     public static final int VK_F22 = 0xF009;
413  
414     /**
415      * Constant for the F23 function key.
416      * @since 1.2
417      */

418     public static final int VK_F23 = 0xF00A;
419  
420     /**
421      * Constant for the F24 function key.
422      * @since 1.2
423      */

424     public static final int VK_F24 = 0xF00B;
425  
426     public static final int VK_PRINTSCREEN = 0x9A;
427     public static final int VK_INSERT = 0x9B;
428     public static final int VK_HELP = 0x9C;
429     public static final int VK_META = 0x9D;
430
431     public static final int VK_BACK_QUOTE = 0xC0;
432     public static final int VK_QUOTE = 0xDE;
433
434     /**
435      * Constant for the numeric keypad <b>up</b> arrow key.
436      * @see #VK_UP
437      * @since 1.2
438      */

439     public static final int VK_KP_UP = 0xE0;
440
441     /**
442      * Constant for the numeric keypad <b>down</b> arrow key.
443      * @see #VK_DOWN
444      * @since 1.2
445      */

446     public static final int VK_KP_DOWN = 0xE1;
447
448     /**
449      * Constant for the numeric keypad <b>left</b> arrow key.
450      * @see #VK_LEFT
451      * @since 1.2
452      */

453     public static final int VK_KP_LEFT = 0xE2;
454
455     /**
456      * Constant for the numeric keypad <b>right</b> arrow key.
457      * @see #VK_RIGHT
458      * @since 1.2
459      */

460     public static final int VK_KP_RIGHT = 0xE3;
461     
462     /* For European keyboards */
463     /** @since 1.2 */
464     public static final int VK_DEAD_GRAVE = 0x80;
465     /** @since 1.2 */
466     public static final int VK_DEAD_ACUTE = 0x81;
467     /** @since 1.2 */
468     public static final int VK_DEAD_CIRCUMFLEX = 0x82;
469     /** @since 1.2 */
470     public static final int VK_DEAD_TILDE = 0x83;
471     /** @since 1.2 */
472     public static final int VK_DEAD_MACRON = 0x84;
473     /** @since 1.2 */
474     public static final int VK_DEAD_BREVE = 0x85;
475     /** @since 1.2 */
476     public static final int VK_DEAD_ABOVEDOT = 0x86;
477     /** @since 1.2 */
478     public static final int VK_DEAD_DIAERESIS = 0x87;
479     /** @since 1.2 */
480     public static final int VK_DEAD_ABOVERING = 0x88;
481     /** @since 1.2 */
482     public static final int VK_DEAD_DOUBLEACUTE = 0x89;
483     /** @since 1.2 */
484     public static final int VK_DEAD_CARON = 0x8a;
485     /** @since 1.2 */
486     public static final int VK_DEAD_CEDILLA = 0x8b;
487     /** @since 1.2 */
488     public static final int VK_DEAD_OGONEK = 0x8c;
489     /** @since 1.2 */
490     public static final int VK_DEAD_IOTA = 0x8d;
491     /** @since 1.2 */
492     public static final int VK_DEAD_VOICED_SOUND = 0x8e;
493     /** @since 1.2 */
494     public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f;
495
496     /** @since 1.2 */
497     public static final int VK_AMPERSAND = 0x96;
498     /** @since 1.2 */
499     public static final int VK_ASTERISK = 0x97;
500     /** @since 1.2 */
501     public static final int VK_QUOTEDBL = 0x98;
502     /** @since 1.2 */
503     public static final int VK_LESS = 0x99;
504
505     /** @since 1.2 */
506     public static final int VK_GREATER = 0xa0;
507     /** @since 1.2 */
508     public static final int VK_BRACELEFT = 0xa1;
509     /** @since 1.2 */
510     public static final int VK_BRACERIGHT = 0xa2;
511
512     /**
513      * Constant for the "@" key.
514      * @since 1.2
515      */

516     public static final int VK_AT = 0x0200;
517  
518     /**
519      * Constant for the ":" key.
520      * @since 1.2
521      */

522     public static final int VK_COLON = 0x0201;
523  
524     /**
525      * Constant for the "^" key.
526      * @since 1.2
527      */

528     public static final int VK_CIRCUMFLEX = 0x0202;
529  
530     /**
531      * Constant for the "$" key.
532      * @since 1.2
533      */

534     public static final int VK_DOLLAR = 0x0203;
535  
536     /**
537      * Constant for the Euro currency sign key.
538      * @since 1.2
539      */

540     public static final int VK_EURO_SIGN = 0x0204;
541  
542     /**
543      * Constant for the "!" key.
544      * @since 1.2
545      */

546     public static final int VK_EXCLAMATION_MARK = 0x0205;
547  
548     /**
549      * Constant for the inverted exclamation mark key.
550      * @since 1.2
551      */

552     public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206;
553  
554     /**
555      * Constant for the "(" key.
556      * @since 1.2
557      */

558     public static final int VK_LEFT_PARENTHESIS = 0x0207;
559  
560     /**
561      * Constant for the "#" key.
562      * @since 1.2
563      */

564     public static final int VK_NUMBER_SIGN = 0x0208;
565  
566     /**
567      * Constant for the "+" key.
568      * @since 1.2
569      */

570     public static final int VK_PLUS = 0x0209;
571  
572     /**
573      * Constant for the ")" key.
574      * @since 1.2
575      */

576     public static final int VK_RIGHT_PARENTHESIS = 0x020A;
577  
578     /**
579      * Constant for the "_" key.
580      * @since 1.2
581      */

582     public static final int VK_UNDERSCORE = 0x020B;
583  
584     /**
585      * Constant for the Microsoft Windows "Windows" key.
586      * It is used for both the left and right version of the key.
587      * @see #getKeyLocation()
588      * @since 1.5
589      */

590     public static final int VK_WINDOWS = 0x020C;
591  
592     /**
593      * Constant for the Microsoft Windows Context Menu key.
594      * @since 1.5
595      */

596     public static final int VK_CONTEXT_MENU = 0x020D;
597  
598     /* for input method support on Asian Keyboards */
599
600     /* not clear what this means - listed in Microsoft Windows API */
601     public static final int VK_FINAL = 0x0018;
602     
603     /** Constant for the Convert function key. */
604     /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */
605     public static final int VK_CONVERT = 0x001C;
606
607     /** Constant for the Don't Convert function key. */
608     /* Japanese PC 106 keyboard: muhenkan */
609     public static final int VK_NONCONVERT = 0x001D;
610     
611     /** Constant for the Accept or Commit function key. */
612     /* Japanese Solaris keyboard: kakutei */
613     public static final int VK_ACCEPT = 0x001E;
614
615     /* not clear what this means - listed in Microsoft Windows API */
616     public static final int VK_MODECHANGE = 0x001F;
617
618     /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris;
619        might still be used on other platforms */

620     public static final int VK_KANA = 0x0015;
621
622     /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris;
623        might still be used for other platforms */

624     public static final int VK_KANJI = 0x0019;
625
626     /**
627      * Constant for the Alphanumeric function key.
628      * @since 1.2
629      */

630     /* Japanese PC 106 keyboard: eisuu */
631     public static final int VK_ALPHANUMERIC = 0x00F0;
632  
633     /**
634      * Constant for the Katakana function key.
635      * @since 1.2
636      */

637     /* Japanese PC 106 keyboard: katakana */
638     public static final int VK_KATAKANA = 0x00F1;
639  
640     /**
641      * Constant for the Hiragana function key.
642      * @since 1.2
643      */

644     /* Japanese PC 106 keyboard: hiragana */
645     public static final int VK_HIRAGANA = 0x00F2;
646  
647     /**
648      * Constant for the Full-Width Characters function key.
649      * @since 1.2
650      */

651     /* Japanese PC 106 keyboard: zenkaku */
652     public static final int VK_FULL_WIDTH = 0x00F3;
653  
654     /**
655      * Constant for the Half-Width Characters function key.
656      * @since 1.2
657      */

658     /* Japanese PC 106 keyboard: hankaku */
659     public static final int VK_HALF_WIDTH = 0x00F4;
660  
661     /**
662      * Constant for the Roman Characters function key.
663      * @since 1.2
664      */

665     /* Japanese PC 106 keyboard: roumaji */
666     public static final int VK_ROMAN_CHARACTERS = 0x00F5;
667  
668     /**
669      * Constant for the All Candidates function key.
670      * @since 1.2
671      */

672     /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */
673     public static final int VK_ALL_CANDIDATES = 0x0100;
674  
675     /**
676      * Constant for the Previous Candidate function key.
677      * @since 1.2
678      */

679     /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */
680     public static final int VK_PREVIOUS_CANDIDATE = 0x0101;
681  
682     /**
683      * Constant for the Code Input function key.
684      * @since 1.2
685      */

686     /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */
687     public static final int VK_CODE_INPUT = 0x0102;
688  
689     /**
690      * Constant for the Japanese-Katakana function key.
691      * This key switches to a Japanese input method and selects its Katakana input mode.
692      * @since 1.2
693      */

694     /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */
695     public static final int VK_JAPANESE_KATAKANA = 0x0103;
696  
697     /**
698      * Constant for the Japanese-Hiragana function key.
699      * This key switches to a Japanese input method and selects its Hiragana input mode.
700      * @since 1.2
701      */

702     /* Japanese Macintosh keyboard */
703     public static final int VK_JAPANESE_HIRAGANA = 0x0104;
704  
705     /**
706      * Constant for the Japanese-Roman function key.
707      * This key switches to a Japanese input method and selects its Roman-Direct input mode.
708      * @since 1.2
709      */

710     /* Japanese Macintosh keyboard */
711     public static final int VK_JAPANESE_ROMAN = 0x0105;
712
713     /**
714      * Constant for the locking Kana function key.
715      * This key locks the keyboard into a Kana layout.
716      * @since 1.3
717      */

718     /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */
719     public static final int VK_KANA_LOCK = 0x0106;
720
721     /**
722      * Constant for the input method on/off key.
723      * @since 1.3
724      */

725     /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */
726     public static final int VK_INPUT_METHOD_ON_OFF = 0x0107;
727
728     /* for Sun keyboards */
729     /** @since 1.2 */
730     public static final int VK_CUT = 0xFFD1;
731     /** @since 1.2 */
732     public static final int VK_COPY = 0xFFCD;
733     /** @since 1.2 */
734     public static final int VK_PASTE = 0xFFCF;
735     /** @since 1.2 */
736     public static final int VK_UNDO = 0xFFCB;
737     /** @since 1.2 */
738     public static final int VK_AGAIN = 0xFFC9;
739     /** @since 1.2 */
740     public static final int VK_FIND = 0xFFD0;
741     /** @since 1.2 */
742     public static final int VK_PROPS = 0xFFCA;
743     /** @since 1.2 */
744     public static final int VK_STOP = 0xFFC8;
745     
746     /**
747      * Constant for the Compose function key.
748      * @since 1.2
749      */

750     public static final int VK_COMPOSE = 0xFF20;
751  
752     /**
753      * Constant for the AltGraph function key.
754      * @since 1.2
755      */

756     public static final int VK_ALT_GRAPH = 0xFF7E;
757
758     /**
759      * Constant for the Begin key.
760      * @since 1.5
761      */

762     public static final int VK_BEGIN = 0xFF58;
763
764     /**
765      * This value is used to indicate that the keyCode is unknown.
766      * KEY_TYPED events do not have a keyCode value; this value
767      * is used instead.
768      */

769     public static final int VK_UNDEFINED = 0x0;
770
771     /**
772      * KEY_PRESSED and KEY_RELEASED events which do not map to a
773      * valid Unicode character use this for the keyChar value.
774      */

775     public static final char CHAR_UNDEFINED = 0xFFFF;
776
777     /**
778      * A constant indicating that the keyLocation is indeterminate
779      * or not relevant.
780      * <code>KEY_TYPED</code> events do not have a keyLocation; this value
781      * is used instead.
782      * @since 1.4
783      */

784     public static final int KEY_LOCATION_UNKNOWN = 0;
785
786     /**
787      * A constant indicating that the key pressed or released
788      * is not distinguished as the left or right version of a key,
789      * and did not originate on the numeric keypad (or did not
790      * originate with a virtual key corresponding to the numeric
791      * keypad).
792      * @since 1.4
793      */

794     public static final int KEY_LOCATION_STANDARD = 1;
795
796     /**
797      * A constant indicating that the key pressed or released is in
798      * the left key location (there is more than one possible location
799      * for this key). Example: the left shift key.
800      * @since 1.4
801      */

802     public static final int KEY_LOCATION_LEFT = 2;
803
804     /**
805      * A constant indicating that the key pressed or released is in
806      * the right key location (there is more than one possible location
807      * for this key). Example: the right shift key.
808      * @since 1.4
809      */

810     public static final int KEY_LOCATION_RIGHT = 3;
811
812     /**
813      * A constant indicating that the key event originated on the
814      * numeric keypad or with a virtual key corresponding to the
815      * numeric keypad.
816      * @since 1.4
817      */

818     public static final int KEY_LOCATION_NUMPAD = 4;
819
820     /**
821      * The unique value assigned to each of the keys on the
822      * keyboard. There is a common set of key codes that
823      * can be fired by most keyboards.
824      * The symbolic name for a key code should be used rather
825      * than the code value itself.
826      *
827      * @serial
828      * @see #getKeyCode()
829      * @see #setKeyCode(int)
830      */

831     int keyCode;
832
833     /**
834      * <code>keyChar</code> is a valid unicode character
835      * that is fired by a key or a key combination on
836      * a keyboard.
837      *
838      * @serial
839      * @see #getKeyChar()
840      * @see #setKeyChar(char)
841      */

842     char keyChar;
843
844     /**
845      * The location of the key on the keyboard.
846      *
847      * Some keys occur more than once on a keyboard, e.g. the left and
848      * right shift keys. Additionally, some keys occur on the numeric
849      * keypad. This variable is used to distinguish such keys.
850      *
851      * The only legal values are <code>KEY_LOCATION_UNKNOWN</code>,
852      * <code>KEY_LOCATION_STANDARD</code>, <code>KEY_LOCATION_LEFT</code>,
853      * <code>KEY_LOCATION_RIGHT</code>, and <code>KEY_LOCATION_NUMPAD</code>.
854      *
855      * @serial
856      * @see #getKeyLocation()
857      */

858     int keyLocation;
859
860     //set from native code.
861
private transient long rawCode = 0;
862
863     /*
864      * JDK 1.1 serialVersionUID
865      */

866     private static final long serialVersionUID = -2352130953028126954L;
867
868     static {
869         /* ensure that the necessary native libraries are loaded */
870     NativeLibLoader.loadLibraries();
871         if (!GraphicsEnvironment.isHeadless()) {
872             initIDs();
873         }
874     }
875
876     /**
877      * Initialize JNI field and method IDs for fields that may be
878      * accessed from C.
879      */

880     private static native void initIDs();
881
882     /**
883      * Constructs a <code>KeyEvent</code> object.
884      * <p>Note that passing in an invalid <code>id</code> results in
885      * unspecified behavior. This method throws an
886      * <code>IllegalArgumentException</code> if <code>source</code>
887      * is <code>null</code>.
888      *
889      * @param source the <code>Component</code> that originated the event
890      * @param id an integer identifying the type of event
891      * @param when a long integer that specifies the time the event
892      * occurred
893      * @param modifiers the modifier keys down during event (shift, ctrl,
894      * alt, meta)
895      * Either extended _DOWN_MASK or old _MASK modifiers
896      * should be used, but both models should not be mixed
897      * in one event. Use of the extended modifiers is
898      * preferred.
899      * @param keyCode the integer code for an actual key, or VK_UNDEFINED
900      * (for a key-typed event)
901      * @param keyChar the Unicode character generated by this event, or
902      * CHAR_UNDEFINED (for key-pressed and key-released
903      * events which do not map to a valid Unicode character)
904      * @param keyLocation identifies the key location. The only legal
905      * values are <code>KEY_LOCATION_UNKNOWN</code>,
906      * <code>KEY_LOCATION_STANDARD</code>, <code>KEY_LOCATION_LEFT</code>,
907      * <code>KEY_LOCATION_RIGHT</code>, and <code>KEY_LOCATION_NUMPAD</code>.
908      * @throws IllegalArgumentException
909      * if <code>id</code> is <code>KEY_TYPED</code> and
910      * <code>keyChar</code> is <code>CHAR_UNDEFINED</code>;
911      * or if <code>id</code> is <code>KEY_TYPED</code> and
912      * <code>keyCode</code> is not <code>VK_UNDEFINED</code>;
913      * or if <code>id</code> is <code>KEY_TYPED</code> and
914      * <code>keyLocation</code> is not <code>KEY_LOCATION_UNKNOWN</code>;
915      * or if <code>keyLocation</code> is not one of the legal
916      * values enumerated above.
917      * @throws IllegalArgumentException if <code>source</code> is null
918      * @since 1.4
919      */

920     private KeyEvent(Component JavaDoc source, int id, long when, int modifiers,
921                     int keyCode, char keyChar, int keyLocation, boolean isProxyActive) {
922         this(source, id, when, modifiers, keyCode, keyChar, keyLocation);
923         this.isProxyActive = isProxyActive;
924     }
925     public KeyEvent(Component JavaDoc source, int id, long when, int modifiers,
926                     int keyCode, char keyChar, int keyLocation) {
927         super(source, id, when, modifiers);
928         if (id == KEY_TYPED) {
929             if (keyChar == CHAR_UNDEFINED) {
930