1 /*
   2  * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.event;
  27 
  28 import java.awt.Event;
  29 import java.awt.Component;
  30 import java.awt.GraphicsEnvironment;
  31 import java.awt.Toolkit;
  32 import java.io.IOException;
  33 import java.io.ObjectInputStream;
  34 
  35 /**
  36  * An event which indicates that a keystroke occurred in a component.
  37  * <p>
  38  * This low-level event is generated by a component object (such as a text
  39  * field) when a key is pressed, released, or typed.
  40  * The event is passed to every <code>KeyListener</code>
  41  * or <code>KeyAdapter</code> object which registered to receive such
  42  * events using the component's <code>addKeyListener</code> method.
  43  * (<code>KeyAdapter</code> objects implement the
  44  * <code>KeyListener</code> interface.)  Each such listener object
  45  * gets this <code>KeyEvent</code> when the event occurs.
  46  * <p>
  47  * <em>"Key typed" events</em> are higher-level and generally do not depend on
  48  * the platform or keyboard layout.  They are generated when a Unicode character
  49  * is entered, and are the preferred way to find out about character input.
  50  * In the simplest case, a key typed event is produced by a single key press
  51  * (e.g., 'a').  Often, however, characters are produced by series of key
  52  * presses (e.g., 'shift' + 'a'), and the mapping from key pressed events to
  53  * key typed events may be many-to-one or many-to-many.  Key releases are not
  54  * usually necessary to generate a key typed event, but there are some cases
  55  * where the key typed event is not generated until a key is released (e.g.,
  56  * entering ASCII sequences via the Alt-Numpad method in Windows).
  57  * No key typed events are generated for keys that don't generate Unicode
  58  * characters (e.g., action keys, modifier keys, etc.).
  59  * <p>
  60  * The getKeyChar method always returns a valid Unicode character or
  61  * CHAR_UNDEFINED.  Character input is reported by KEY_TYPED events:
  62  * KEY_PRESSED and KEY_RELEASED events are not necessarily associated
  63  * with character input.  Therefore, the result of the getKeyChar method
  64  * is guaranteed to be meaningful only for KEY_TYPED events.
  65  * <p>
  66  * For key pressed and key released events, the getKeyCode method returns
  67  * the event's keyCode.  For key typed events, the getKeyCode method
  68  * always returns VK_UNDEFINED.
  69  *
  70  * <p>
  71  * <em>"Key pressed" and "key released" events</em> are lower-level and depend
  72  * on the platform and keyboard layout. They are generated whenever a key is
  73  * pressed or released, and are the only way to find out about keys that don't
  74  * generate character input (e.g., action keys, modifier keys, etc.). The key
  75  * being pressed or released is indicated by the getKeyCode method, which returns
  76  * a virtual key code.
  77  *
  78  * <p>
  79  * <em>Virtual key codes</em> are used to report which keyboard key has
  80  * been pressed, rather than a character generated by the combination
  81  * of one or more keystrokes (such as "A", which comes from shift and "a").
  82  *
  83  * <p>
  84  * For example, pressing the Shift key will cause a KEY_PRESSED event
  85  * with a VK_SHIFT keyCode, while pressing the 'a' key will result in
  86  * a VK_A keyCode.  After the 'a' key is released, a KEY_RELEASED event
  87  * will be fired with VK_A. Separately, a KEY_TYPED event with a keyChar
  88  * value of 'A' is generated.
  89  *
  90  * <p>
  91  * Pressing and releasing a key on the keyboard results in the generating
  92  * the following key events (in order):
  93  * <PRE>
  94  *    {@code KEY_PRESSED}
  95  *    {@code KEY_TYPED} (is only generated if a valid Unicode character could be generated.)
  96  *    {@code KEY_RELEASED}
  97  * </PRE>
  98  *
  99  * But in some cases (e.g. auto-repeat or input method is activated) the order
 100  * could be different (and platform dependent).
 101  *
 102  * <p>
 103  * Notes:
 104  * <ul>
 105  * <li>Key combinations which do not result in Unicode characters, such as action
 106  * keys like F1 and the HELP key, do not generate KEY_TYPED events.
 107  * <li>Not all keyboards or systems are capable of generating all
 108  * virtual key codes.  No attempt is made in Java to generate these keys
 109  * artificially.
 110  * <li>Virtual key codes do not identify a physical key: they depend on the
 111  * platform and keyboard layout. For example, the key that generates VK_Q
 112  * when using a U.S. keyboard layout will generate VK_A when using a French
 113  * keyboard layout.
 114  * <li>Not all characters have a keycode associated with them.  For example,
 115  * there is no keycode for the question mark because there is no keyboard
 116  * for which it appears on the primary layer.
 117  * <li>In order to support the platform-independent handling of action keys,
 118  * the Java platform uses a few additional virtual key constants for functions
 119  * that would otherwise have to be recognized by interpreting virtual key codes
 120  * and modifiers. For example, for Japanese Windows keyboards, VK_ALL_CANDIDATES
 121  * is returned instead of VK_CONVERT with the ALT modifier.
 122  * <li>As specified in <a href="../doc-files/FocusSpec.html">Focus Specification</a>
 123  * key events are dispatched to the focus owner by default.
 124  * </ul>
 125  *
 126  * <p>
 127  * WARNING: Aside from those keys that are defined by the Java language
 128  * (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of the VK_
 129  * constants.  Sun reserves the right to change these values as needed
 130  * to accomodate a wider range of keyboards in the future.
 131  *
 132  * @author Carl Quinn
 133  * @author Amy Fowler
 134  * @author Norbert Lindenberg
 135  *
 136  * @see KeyAdapter
 137  * @see KeyListener
 138  * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/keylistener.html">Tutorial: Writing a Key Listener</a>
 139  *
 140  * @since 1.1
 141  */
 142 public class KeyEvent extends InputEvent {
 143 
 144     /**
 145      * Stores the state of native event dispatching system
 146      * - true, if when the event was created event proxying
 147      *         mechanism was active
 148      * - false, if it was inactive
 149      * Used in Component.dispatchEventImpl to correctly dispatch
 150      * events when proxy is active
 151      */
 152     private boolean isProxyActive = false;
 153 
 154     /**
 155      * The first number in the range of ids used for key events.
 156      */
 157     public static final int KEY_FIRST = 400;
 158 
 159     /**
 160      * The last number in the range of ids used for key events.
 161      */
 162     public static final int KEY_LAST  = 402;
 163 
 164     /**
 165      * The "key typed" event.  This event is generated when a character is
 166      * entered.  In the simplest case, it is produced by a single key press.
 167      * Often, however, characters are produced by series of key presses, and
 168      * the mapping from key pressed events to key typed events may be
 169      * many-to-one or many-to-many.
 170      */
 171     public static final int KEY_TYPED = KEY_FIRST;
 172 
 173     /**
 174      * The "key pressed" event. This event is generated when a key
 175      * is pushed down.
 176      */
 177     public static final int KEY_PRESSED = 1 + KEY_FIRST; //Event.KEY_PRESS
 178 
 179     /**
 180      * The "key released" event. This event is generated when a key
 181      * is let up.
 182      */
 183     public static final int KEY_RELEASED = 2 + KEY_FIRST; //Event.KEY_RELEASE
 184 
 185     /* Virtual key codes. */
 186 
 187     public static final int VK_ENTER          = '\n';
 188     public static final int VK_BACK_SPACE     = '\b';
 189     public static final int VK_TAB            = '\t';
 190     public static final int VK_CANCEL         = 0x03;
 191     public static final int VK_CLEAR          = 0x0C;
 192     public static final int VK_SHIFT          = 0x10;
 193     public static final int VK_CONTROL        = 0x11;
 194     public static final int VK_ALT            = 0x12;
 195     public static final int VK_PAUSE          = 0x13;
 196     public static final int VK_CAPS_LOCK      = 0x14;
 197     public static final int VK_ESCAPE         = 0x1B;
 198     public static final int VK_SPACE          = 0x20;
 199     public static final int VK_PAGE_UP        = 0x21;
 200     public static final int VK_PAGE_DOWN      = 0x22;
 201     public static final int VK_END            = 0x23;
 202     public static final int VK_HOME           = 0x24;
 203 
 204     /**
 205      * Constant for the non-numpad <b>left</b> arrow key.
 206      * @see #VK_KP_LEFT
 207      */
 208     public static final int VK_LEFT           = 0x25;
 209 
 210     /**
 211      * Constant for the non-numpad <b>up</b> arrow key.
 212      * @see #VK_KP_UP
 213      */
 214     public static final int VK_UP             = 0x26;
 215 
 216     /**
 217      * Constant for the non-numpad <b>right</b> arrow key.
 218      * @see #VK_KP_RIGHT
 219      */
 220     public static final int VK_RIGHT          = 0x27;
 221 
 222     /**
 223      * Constant for the non-numpad <b>down</b> arrow key.
 224      * @see #VK_KP_DOWN
 225      */
 226     public static final int VK_DOWN           = 0x28;
 227 
 228     /**
 229      * Constant for the comma key, ","
 230      */
 231     public static final int VK_COMMA          = 0x2C;
 232 
 233     /**
 234      * Constant for the minus key, "-"
 235      * @since 1.2
 236      */
 237     public static final int VK_MINUS          = 0x2D;
 238 
 239     /**
 240      * Constant for the period key, "."
 241      */
 242     public static final int VK_PERIOD         = 0x2E;
 243 
 244     /**
 245      * Constant for the forward slash key, "/"
 246      */
 247     public static final int VK_SLASH          = 0x2F;
 248 
 249     /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
 250     public static final int VK_0              = 0x30;
 251     public static final int VK_1              = 0x31;
 252     public static final int VK_2              = 0x32;
 253     public static final int VK_3              = 0x33;
 254     public static final int VK_4              = 0x34;
 255     public static final int VK_5              = 0x35;
 256     public static final int VK_6              = 0x36;
 257     public static final int VK_7              = 0x37;
 258     public static final int VK_8              = 0x38;
 259     public static final int VK_9              = 0x39;
 260 
 261     /**
 262      * Constant for the semicolon key, ";"
 263      */
 264     public static final int VK_SEMICOLON      = 0x3B;
 265 
 266     /**
 267      * Constant for the equals key, "="
 268      */
 269     public static final int VK_EQUALS         = 0x3D;
 270 
 271     /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
 272     public static final int VK_A              = 0x41;
 273     public static final int VK_B              = 0x42;
 274     public static final int VK_C              = 0x43;
 275     public static final int VK_D              = 0x44;
 276     public static final int VK_E              = 0x45;
 277     public static final int VK_F              = 0x46;
 278     public static final int VK_G              = 0x47;
 279     public static final int VK_H              = 0x48;
 280     public static final int VK_I              = 0x49;
 281     public static final int VK_J              = 0x4A;
 282     public static final int VK_K              = 0x4B;
 283     public static final int VK_L              = 0x4C;
 284     public static final int VK_M              = 0x4D;
 285     public static final int VK_N              = 0x4E;
 286     public static final int VK_O              = 0x4F;
 287     public static final int VK_P              = 0x50;
 288     public static final int VK_Q              = 0x51;
 289     public static final int VK_R              = 0x52;
 290     public static final int VK_S              = 0x53;
 291     public static final int VK_T              = 0x54;
 292     public static final int VK_U              = 0x55;
 293     public static final int VK_V              = 0x56;
 294     public static final int VK_W              = 0x57;
 295     public static final int VK_X              = 0x58;
 296     public static final int VK_Y              = 0x59;
 297     public static final int VK_Z              = 0x5A;
 298 
 299     /**
 300      * Constant for the open bracket key, "["
 301      */
 302     public static final int VK_OPEN_BRACKET   = 0x5B;
 303 
 304     /**
 305      * Constant for the back slash key, "\"
 306      */
 307     public static final int VK_BACK_SLASH     = 0x5C;
 308 
 309     /**
 310      * Constant for the close bracket key, "]"
 311      */
 312     public static final int VK_CLOSE_BRACKET  = 0x5D;
 313 
 314     public static final int VK_NUMPAD0        = 0x60;
 315     public static final int VK_NUMPAD1        = 0x61;
 316     public static final int VK_NUMPAD2        = 0x62;
 317     public static final int VK_NUMPAD3        = 0x63;
 318     public static final int VK_NUMPAD4        = 0x64;
 319     public static final int VK_NUMPAD5        = 0x65;
 320     public static final int VK_NUMPAD6        = 0x66;
 321     public static final int VK_NUMPAD7        = 0x67;
 322     public static final int VK_NUMPAD8        = 0x68;
 323     public static final int VK_NUMPAD9        = 0x69;
 324     public static final int VK_MULTIPLY       = 0x6A;
 325     public static final int VK_ADD            = 0x6B;
 326 
 327     /**
 328      * This constant is obsolete, and is included only for backwards
 329      * compatibility.
 330      * @see #VK_SEPARATOR
 331      */
 332     public static final int VK_SEPARATER      = 0x6C;
 333 
 334     /**
 335      * Constant for the Numpad Separator key.
 336      * @since 1.4
 337      */
 338     public static final int VK_SEPARATOR      = VK_SEPARATER;
 339 
 340     public static final int VK_SUBTRACT       = 0x6D;
 341     public static final int VK_DECIMAL        = 0x6E;
 342     public static final int VK_DIVIDE         = 0x6F;
 343     public static final int VK_DELETE         = 0x7F; /* ASCII DEL */
 344     public static final int VK_NUM_LOCK       = 0x90;
 345     public static final int VK_SCROLL_LOCK    = 0x91;
 346 
 347     /** Constant for the F1 function key. */
 348     public static final int VK_F1             = 0x70;
 349 
 350     /** Constant for the F2 function key. */
 351     public static final int VK_F2             = 0x71;
 352 
 353     /** Constant for the F3 function key. */
 354     public static final int VK_F3             = 0x72;
 355 
 356     /** Constant for the F4 function key. */
 357     public static final int VK_F4             = 0x73;
 358 
 359     /** Constant for the F5 function key. */
 360     public static final int VK_F5             = 0x74;
 361 
 362     /** Constant for the F6 function key. */
 363     public static final int VK_F6             = 0x75;
 364 
 365     /** Constant for the F7 function key. */
 366     public static final int VK_F7             = 0x76;
 367 
 368     /** Constant for the F8 function key. */
 369     public static final int VK_F8             = 0x77;
 370 
 371     /** Constant for the F9 function key. */
 372     public static final int VK_F9             = 0x78;
 373 
 374     /** Constant for the F10 function key. */
 375     public static final int VK_F10            = 0x79;
 376 
 377     /** Constant for the F11 function key. */
 378     public static final int VK_F11            = 0x7A;
 379 
 380     /** Constant for the F12 function key. */
 381     public static final int VK_F12            = 0x7B;
 382 
 383     /**
 384      * Constant for the F13 function key.
 385      * @since 1.2
 386      */
 387     /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */
 388     public static final int VK_F13            = 0xF000;
 389 
 390     /**
 391      * Constant for the F14 function key.
 392      * @since 1.2
 393      */
 394     public static final int VK_F14            = 0xF001;
 395 
 396     /**
 397      * Constant for the F15 function key.
 398      * @since 1.2
 399      */
 400     public static final int VK_F15            = 0xF002;
 401 
 402     /**
 403      * Constant for the F16 function key.
 404      * @since 1.2
 405      */
 406     public static final int VK_F16            = 0xF003;
 407 
 408     /**
 409      * Constant for the F17 function key.
 410      * @since 1.2
 411      */
 412     public static final int VK_F17            = 0xF004;
 413 
 414     /**
 415      * Constant for the F18 function key.
 416      * @since 1.2
 417      */
 418     public static final int VK_F18            = 0xF005;
 419 
 420     /**
 421      * Constant for the F19 function key.
 422      * @since 1.2
 423      */
 424     public static final int VK_F19            = 0xF006;
 425 
 426     /**
 427      * Constant for the F20 function key.
 428      * @since 1.2
 429      */
 430     public static final int VK_F20            = 0xF007;
 431 
 432     /**
 433      * Constant for the F21 function key.
 434      * @since 1.2
 435      */
 436     public static final int VK_F21            = 0xF008;
 437 
 438     /**
 439      * Constant for the F22 function key.
 440      * @since 1.2
 441      */
 442     public static final int VK_F22            = 0xF009;
 443 
 444     /**
 445      * Constant for the F23 function key.
 446      * @since 1.2
 447      */
 448     public static final int VK_F23            = 0xF00A;
 449 
 450     /**
 451      * Constant for the F24 function key.
 452      * @since 1.2
 453      */
 454     public static final int VK_F24            = 0xF00B;
 455 
 456     public static final int VK_PRINTSCREEN    = 0x9A;
 457     public static final int VK_INSERT         = 0x9B;
 458     public static final int VK_HELP           = 0x9C;
 459     public static final int VK_META           = 0x9D;
 460 
 461     public static final int VK_BACK_QUOTE     = 0xC0;
 462     public static final int VK_QUOTE          = 0xDE;
 463 
 464     /**
 465      * Constant for the numeric keypad <b>up</b> arrow key.
 466      * @see #VK_UP
 467      * @since 1.2
 468      */
 469     public static final int VK_KP_UP          = 0xE0;
 470 
 471     /**
 472      * Constant for the numeric keypad <b>down</b> arrow key.
 473      * @see #VK_DOWN
 474      * @since 1.2
 475      */
 476     public static final int VK_KP_DOWN        = 0xE1;
 477 
 478     /**
 479      * Constant for the numeric keypad <b>left</b> arrow key.
 480      * @see #VK_LEFT
 481      * @since 1.2
 482      */
 483     public static final int VK_KP_LEFT        = 0xE2;
 484 
 485     /**
 486      * Constant for the numeric keypad <b>right</b> arrow key.
 487      * @see #VK_RIGHT
 488      * @since 1.2
 489      */
 490     public static final int VK_KP_RIGHT       = 0xE3;
 491 
 492     /* For European keyboards */
 493     /** @since 1.2 */
 494     public static final int VK_DEAD_GRAVE               = 0x80;
 495     /** @since 1.2 */
 496     public static final int VK_DEAD_ACUTE               = 0x81;
 497     /** @since 1.2 */
 498     public static final int VK_DEAD_CIRCUMFLEX          = 0x82;
 499     /** @since 1.2 */
 500     public static final int VK_DEAD_TILDE               = 0x83;
 501     /** @since 1.2 */
 502     public static final int VK_DEAD_MACRON              = 0x84;
 503     /** @since 1.2 */
 504     public static final int VK_DEAD_BREVE               = 0x85;
 505     /** @since 1.2 */
 506     public static final int VK_DEAD_ABOVEDOT            = 0x86;
 507     /** @since 1.2 */
 508     public static final int VK_DEAD_DIAERESIS           = 0x87;
 509     /** @since 1.2 */
 510     public static final int VK_DEAD_ABOVERING           = 0x88;
 511     /** @since 1.2 */
 512     public static final int VK_DEAD_DOUBLEACUTE         = 0x89;
 513     /** @since 1.2 */
 514     public static final int VK_DEAD_CARON               = 0x8a;
 515     /** @since 1.2 */
 516     public static final int VK_DEAD_CEDILLA             = 0x8b;
 517     /** @since 1.2 */
 518     public static final int VK_DEAD_OGONEK              = 0x8c;
 519     /** @since 1.2 */
 520     public static final int VK_DEAD_IOTA                = 0x8d;
 521     /** @since 1.2 */
 522     public static final int VK_DEAD_VOICED_SOUND        = 0x8e;
 523     /** @since 1.2 */
 524     public static final int VK_DEAD_SEMIVOICED_SOUND    = 0x8f;
 525 
 526     /** @since 1.2 */
 527     public static final int VK_AMPERSAND                = 0x96;
 528     /** @since 1.2 */
 529     public static final int VK_ASTERISK                 = 0x97;
 530     /** @since 1.2 */
 531     public static final int VK_QUOTEDBL                 = 0x98;
 532     /** @since 1.2 */
 533     public static final int VK_LESS                     = 0x99;
 534 
 535     /** @since 1.2 */
 536     public static final int VK_GREATER                  = 0xa0;
 537     /** @since 1.2 */
 538     public static final int VK_BRACELEFT                = 0xa1;
 539     /** @since 1.2 */
 540     public static final int VK_BRACERIGHT               = 0xa2;
 541 
 542     /**
 543      * Constant for the "@" key.
 544      * @since 1.2
 545      */
 546     public static final int VK_AT                       = 0x0200;
 547 
 548     /**
 549      * Constant for the ":" key.
 550      * @since 1.2
 551      */
 552     public static final int VK_COLON                    = 0x0201;
 553 
 554     /**
 555      * Constant for the "^" key.
 556      * @since 1.2
 557      */
 558     public static final int VK_CIRCUMFLEX               = 0x0202;
 559 
 560     /**
 561      * Constant for the "$" key.
 562      * @since 1.2
 563      */
 564     public static final int VK_DOLLAR                   = 0x0203;
 565 
 566     /**
 567      * Constant for the Euro currency sign key.
 568      * @since 1.2
 569      */
 570     public static final int VK_EURO_SIGN                = 0x0204;
 571 
 572     /**
 573      * Constant for the "!" key.
 574      * @since 1.2
 575      */
 576     public static final int VK_EXCLAMATION_MARK         = 0x0205;
 577 
 578     /**
 579      * Constant for the inverted exclamation mark key.
 580      * @since 1.2
 581      */
 582     public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206;
 583 
 584     /**
 585      * Constant for the "(" key.
 586      * @since 1.2
 587      */
 588     public static final int VK_LEFT_PARENTHESIS         = 0x0207;
 589 
 590     /**
 591      * Constant for the "#" key.
 592      * @since 1.2
 593      */
 594     public static final int VK_NUMBER_SIGN              = 0x0208;
 595 
 596     /**
 597      * Constant for the "+" key.
 598      * @since 1.2
 599      */
 600     public static final int VK_PLUS                     = 0x0209;
 601 
 602     /**
 603      * Constant for the ")" key.
 604      * @since 1.2
 605      */
 606     public static final int VK_RIGHT_PARENTHESIS        = 0x020A;
 607 
 608     /**
 609      * Constant for the "_" key.
 610      * @since 1.2
 611      */
 612     public static final int VK_UNDERSCORE               = 0x020B;
 613 
 614     /**
 615      * Constant for the Microsoft Windows "Windows" key.
 616      * It is used for both the left and right version of the key.
 617      * @see #getKeyLocation()
 618      * @since 1.5
 619      */
 620     public static final int VK_WINDOWS                  = 0x020C;
 621 
 622     /**
 623      * Constant for the Microsoft Windows Context Menu key.
 624      * @since 1.5
 625      */
 626     public static final int VK_CONTEXT_MENU             = 0x020D;
 627 
 628     /* for input method support on Asian Keyboards */
 629 
 630     /* not clear what this means - listed in Microsoft Windows API */
 631     public static final int VK_FINAL                    = 0x0018;
 632 
 633     /** Constant for the Convert function key. */
 634     /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */
 635     public static final int VK_CONVERT                  = 0x001C;
 636 
 637     /** Constant for the Don't Convert function key. */
 638     /* Japanese PC 106 keyboard: muhenkan */
 639     public static final int VK_NONCONVERT               = 0x001D;
 640 
 641     /** Constant for the Accept or Commit function key. */
 642     /* Japanese Solaris keyboard: kakutei */
 643     public static final int VK_ACCEPT                   = 0x001E;
 644 
 645     /* not clear what this means - listed in Microsoft Windows API */
 646     public static final int VK_MODECHANGE               = 0x001F;
 647 
 648     /* replaced by VK_KANA_LOCK for Microsoft Windows and Solaris;
 649        might still be used on other platforms */
 650     public static final int VK_KANA                     = 0x0015;
 651 
 652     /* replaced by VK_INPUT_METHOD_ON_OFF for Microsoft Windows and Solaris;
 653        might still be used for other platforms */
 654     public static final int VK_KANJI                    = 0x0019;
 655 
 656     /**
 657      * Constant for the Alphanumeric function key.
 658      * @since 1.2
 659      */
 660     /* Japanese PC 106 keyboard: eisuu */
 661     public static final int VK_ALPHANUMERIC             = 0x00F0;
 662 
 663     /**
 664      * Constant for the Katakana function key.
 665      * @since 1.2
 666      */
 667     /* Japanese PC 106 keyboard: katakana */
 668     public static final int VK_KATAKANA                 = 0x00F1;
 669 
 670     /**
 671      * Constant for the Hiragana function key.
 672      * @since 1.2
 673      */
 674     /* Japanese PC 106 keyboard: hiragana */
 675     public static final int VK_HIRAGANA                 = 0x00F2;
 676 
 677     /**
 678      * Constant for the Full-Width Characters function key.
 679      * @since 1.2
 680      */
 681     /* Japanese PC 106 keyboard: zenkaku */
 682     public static final int VK_FULL_WIDTH               = 0x00F3;
 683 
 684     /**
 685      * Constant for the Half-Width Characters function key.
 686      * @since 1.2
 687      */
 688     /* Japanese PC 106 keyboard: hankaku */
 689     public static final int VK_HALF_WIDTH               = 0x00F4;
 690 
 691     /**
 692      * Constant for the Roman Characters function key.
 693      * @since 1.2
 694      */
 695     /* Japanese PC 106 keyboard: roumaji */
 696     public static final int VK_ROMAN_CHARACTERS         = 0x00F5;
 697 
 698     /**
 699      * Constant for the All Candidates function key.
 700      * @since 1.2
 701      */
 702     /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */
 703     public static final int VK_ALL_CANDIDATES           = 0x0100;
 704 
 705     /**
 706      * Constant for the Previous Candidate function key.
 707      * @since 1.2
 708      */
 709     /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */
 710     public static final int VK_PREVIOUS_CANDIDATE       = 0x0101;
 711 
 712     /**
 713      * Constant for the Code Input function key.
 714      * @since 1.2
 715      */
 716     /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */
 717     public static final int VK_CODE_INPUT               = 0x0102;
 718 
 719     /**
 720      * Constant for the Japanese-Katakana function key.
 721      * This key switches to a Japanese input method and selects its Katakana input mode.
 722      * @since 1.2
 723      */
 724     /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */
 725     public static final int VK_JAPANESE_KATAKANA        = 0x0103;
 726 
 727     /**
 728      * Constant for the Japanese-Hiragana function key.
 729      * This key switches to a Japanese input method and selects its Hiragana input mode.
 730      * @since 1.2
 731      */
 732     /* Japanese Macintosh keyboard */
 733     public static final int VK_JAPANESE_HIRAGANA        = 0x0104;
 734 
 735     /**
 736      * Constant for the Japanese-Roman function key.
 737      * This key switches to a Japanese input method and selects its Roman-Direct input mode.
 738      * @since 1.2
 739      */
 740     /* Japanese Macintosh keyboard */
 741     public static final int VK_JAPANESE_ROMAN           = 0x0105;
 742 
 743     /**
 744      * Constant for the locking Kana function key.
 745      * This key locks the keyboard into a Kana layout.
 746      * @since 1.3
 747      */
 748     /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */
 749     public static final int VK_KANA_LOCK                = 0x0106;
 750 
 751     /**
 752      * Constant for the input method on/off key.
 753      * @since 1.3
 754      */
 755     /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */
 756     public static final int VK_INPUT_METHOD_ON_OFF      = 0x0107;
 757 
 758     /* for Sun keyboards */
 759     /** @since 1.2 */
 760     public static final int VK_CUT                      = 0xFFD1;
 761     /** @since 1.2 */
 762     public static final int VK_COPY                     = 0xFFCD;
 763     /** @since 1.2 */
 764     public static final int VK_PASTE                    = 0xFFCF;
 765     /** @since 1.2 */
 766     public static final int VK_UNDO                     = 0xFFCB;
 767     /** @since 1.2 */
 768     public static final int VK_AGAIN                    = 0xFFC9;
 769     /** @since 1.2 */
 770     public static final int VK_FIND                     = 0xFFD0;
 771     /** @since 1.2 */
 772     public static final int VK_PROPS                    = 0xFFCA;
 773     /** @since 1.2 */
 774     public static final int VK_STOP                     = 0xFFC8;
 775 
 776     /**
 777      * Constant for the Compose function key.
 778      * @since 1.2
 779      */
 780     public static final int VK_COMPOSE                  = 0xFF20;
 781 
 782     /**
 783      * Constant for the AltGraph function key.
 784      * @since 1.2
 785      */
 786     public static final int VK_ALT_GRAPH                = 0xFF7E;
 787 
 788     /**
 789      * Constant for the Begin key.
 790      * @since 1.5
 791      */
 792     public static final int VK_BEGIN                    = 0xFF58;
 793 
 794     /**
 795      * This value is used to indicate that the keyCode is unknown.
 796      * KEY_TYPED events do not have a keyCode value; this value
 797      * is used instead.
 798      */
 799     public static final int VK_UNDEFINED      = 0x0;
 800 
 801     /**
 802      * KEY_PRESSED and KEY_RELEASED events which do not map to a
 803      * valid Unicode character use this for the keyChar value.
 804      */
 805     public static final char CHAR_UNDEFINED   = 0xFFFF;
 806 
 807     /**
 808      * A constant indicating that the keyLocation is indeterminate
 809      * or not relevant.
 810      * <code>KEY_TYPED</code> events do not have a keyLocation; this value
 811      * is used instead.
 812      * @since 1.4
 813      */
 814     public static final int KEY_LOCATION_UNKNOWN  = 0;
 815 
 816     /**
 817      * A constant indicating that the key pressed or released
 818      * is not distinguished as the left or right version of a key,
 819      * and did not originate on the numeric keypad (or did not
 820      * originate with a virtual key corresponding to the numeric
 821      * keypad).
 822      * @since 1.4
 823      */
 824     public static final int KEY_LOCATION_STANDARD = 1;
 825 
 826     /**
 827      * A constant indicating that the key pressed or released is in
 828      * the left key location (there is more than one possible location
 829      * for this key).  Example: the left shift key.
 830      * @since 1.4
 831      */
 832     public static final int KEY_LOCATION_LEFT     = 2;
 833 
 834     /**
 835      * A constant indicating that the key pressed or released is in
 836      * the right key location (there is more than one possible location
 837      * for this key).  Example: the right shift key.
 838      * @since 1.4
 839      */
 840     public static final int KEY_LOCATION_RIGHT    = 3;
 841 
 842     /**
 843      * A constant indicating that the key event originated on the
 844      * numeric keypad or with a virtual key corresponding to the
 845      * numeric keypad.
 846      * @since 1.4
 847      */
 848     public static final int KEY_LOCATION_NUMPAD   = 4;
 849 
 850     /**
 851      * The unique value assigned to each of the keys on the
 852      * keyboard.  There is a common set of key codes that
 853      * can be fired by most keyboards.
 854      * The symbolic name for a key code should be used rather
 855      * than the code value itself.
 856      *
 857      * @serial
 858      * @see #getKeyCode()
 859      * @see #setKeyCode(int)
 860      */
 861     int  keyCode;
 862 
 863     /**
 864      * <code>keyChar</code> is a valid unicode character
 865      * that is fired by a key or a key combination on
 866      * a keyboard.
 867      *
 868      * @serial
 869      * @see #getKeyChar()
 870      * @see #setKeyChar(char)
 871      */
 872     char keyChar;
 873 
 874     /**
 875      * The location of the key on the keyboard.
 876      *
 877      * Some keys occur more than once on a keyboard, e.g. the left and
 878      * right shift keys.  Additionally, some keys occur on the numeric
 879      * keypad.  This variable is used to distinguish such keys.
 880      *
 881      * The only legal values are <code>KEY_LOCATION_UNKNOWN</code>,
 882      * <code>KEY_LOCATION_STANDARD</code>, <code>KEY_LOCATION_LEFT</code>,
 883      * <code>KEY_LOCATION_RIGHT</code>, and <code>KEY_LOCATION_NUMPAD</code>.
 884      *
 885      * @serial
 886      * @see #getKeyLocation()
 887      */
 888     int keyLocation;
 889 
 890     /*
 891      * JDK 1.1 serialVersionUID
 892      */
 893     private static final long serialVersionUID = -2352130953028126954L;
 894 
 895     static {
 896         /* ensure that the necessary native libraries are loaded */
 897         NativeLibLoader.loadLibraries();
 898         if (!GraphicsEnvironment.isHeadless()) {
 899             initIDs();
 900         }
 901     }
 902 
 903     /**
 904      * Initialize JNI field and method IDs for fields that may be
 905      * accessed from C.
 906      */
 907     private static native void initIDs();
 908 
 909     /**
 910      * Constructs a <code>KeyEvent</code> object.
 911      * <p>Note that passing in an invalid <code>id</code> results in
 912      * unspecified behavior. This method throws an
 913      * <code>IllegalArgumentException</code> if <code>source</code>
 914      * is <code>null</code>.
 915      *
 916      * @param source    the <code>Component</code> that originated the event
 917      * @param id        an integer identifying the type of event
 918      * @param when      a long integer that specifies the time the event
 919      *                  occurred
 920      * @param modifiers the modifier keys down during event (shift, ctrl,
 921      *                  alt, meta)
 922      *                  Either extended _DOWN_MASK or old _MASK modifiers
 923      *                  should be used, but both models should not be mixed
 924      *                  in one event. Use of the extended modifiers is
 925      *                  preferred.
 926      * @param keyCode   the integer code for an actual key, or VK_UNDEFINED
 927      *                  (for a key-typed event)
 928      * @param keyChar   the Unicode character generated by this event, or
 929      *                  CHAR_UNDEFINED (for key-pressed and key-released
 930      *                  events which do not map to a valid Unicode character)
 931      * @param keyLocation  identifies the key location.  The only legal
 932      *        values are <code>KEY_LOCATION_UNKNOWN</code>,
 933      *        <code>KEY_LOCATION_STANDARD</code>, <code>KEY_LOCATION_LEFT</code>,
 934      *        <code>KEY_LOCATION_RIGHT</code>, and <code>KEY_LOCATION_NUMPAD</code>.
 935      * @throws IllegalArgumentException
 936      *     if <code>id</code> is <code>KEY_TYPED</code> and
 937      *       <code>keyChar</code> is <code>CHAR_UNDEFINED</code>;
 938      *     or if <code>id</code> is <code>KEY_TYPED</code> and
 939      *       <code>keyCode</code> is not <code>VK_UNDEFINED</code>;
 940      *     or if <code>id</code> is <code>KEY_TYPED</code> and
 941      *       <code>keyLocation</code> is not <code>KEY_LOCATION_UNKNOWN</code>;
 942      *     or if <code>keyLocation</code> is not one of the legal
 943      *       values enumerated above.
 944      * @throws IllegalArgumentException if <code>source</code> is null
 945      * @since 1.4
 946      */
 947     private KeyEvent(Component source, int id, long when, int modifiers,
 948                     int keyCode, char keyChar, int keyLocation, boolean isProxyActive) {
 949         this(source, id, when, modifiers, keyCode, keyChar, keyLocation);
 950         this.isProxyActive = isProxyActive;
 951     }
 952     public KeyEvent(Component source, int id, long when, int modifiers,
 953                     int keyCode, char keyChar, int keyLocation) {
 954         super(source, id, when, modifiers);
 955         if (id == KEY_TYPED) {
 956             if (keyChar == CHAR_UNDEFINED) {
 957                 throw new IllegalArgumentException("invalid keyChar");
 958             }
 959             if (keyCode != VK_UNDEFINED) {
 960                 throw new IllegalArgumentException("invalid keyCode");
 961             }
 962             if (keyLocation != KEY_LOCATION_UNKNOWN) {
 963                 throw new IllegalArgumentException("invalid keyLocation");
 964             }
 965         }
 966 
 967         this.keyCode = keyCode;
 968         this.keyChar = keyChar;
 969 
 970         if ((keyLocation < KEY_LOCATION_UNKNOWN) ||
 971             (keyLocation > KEY_LOCATION_NUMPAD)) {
 972             throw new IllegalArgumentException("invalid keyLocation");
 973         }
 974         this.keyLocation = keyLocation;
 975         if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
 976             setNewModifiers();
 977         } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
 978             setOldModifiers();
 979         }
 980     }
 981 
 982     /**
 983      * Constructs a <code>KeyEvent</code> object.
 984      * <p>Note that passing in an invalid <code>id</code> results in
 985      * unspecified behavior. This method throws an
 986      * <code>IllegalArgumentException</code> if <code>source</code>
 987      * is <code>null</code>.
 988      *
 989      * @param source    the <code>Component</code> that originated the event
 990      * @param id        an integer identifying the type of event
 991      * @param when      a long integer that specifies the time the event
 992      *                  occurred
 993      * @param modifiers the modifier keys down during event (shift, ctrl,
 994      *                  alt, meta)
 995      *                  Either extended _DOWN_MASK or old _MASK modifiers
 996      *                  should be used, but both models should not be mixed
 997      *                  in one event. Use of the extended modifiers is
 998      *                  preferred.
 999      * @param keyCode   the integer code for an actual key, or VK_UNDEFINED
1000      *                  (for a key-typed event)
1001      * @param keyChar   the Unicode character generated by this event, or
1002      *                  CHAR_UNDEFINED (for key-pressed and key-released
1003      *                  events which do not map to a valid Unicode character)
1004      * @throws IllegalArgumentException  if <code>id</code> is
1005      *     <code>KEY_TYPED</code> and <code>keyChar</code> is
1006      *     <code>CHAR_UNDEFINED</code>; or if <code>id</code> is
1007      *     <code>KEY_TYPED</code> and <code>keyCode</code> is not
1008      *     <code>VK_UNDEFINED</code>
1009      * @throws IllegalArgumentException if <code>source</code> is null
1010      */
1011     public KeyEvent(Component source, int id, long when, int modifiers,
1012                     int keyCode, char keyChar) {
1013         this(source, id, when, modifiers, keyCode, keyChar,
1014           KEY_LOCATION_UNKNOWN);
1015     }
1016 
1017     /**
1018      * @deprecated as of JDK1.1
1019      */
1020     @Deprecated
1021     public KeyEvent(Component source, int id, long when, int modifiers,
1022                     int keyCode) {
1023         this(source, id, when, modifiers, keyCode, (char)keyCode);
1024     }
1025 
1026     /**
1027      * Returns the integer keyCode associated with the key in this event.
1028      *
1029      * @return the integer code for an actual key on the keyboard.
1030      *         (For <code>KEY_TYPED</code> events, the keyCode is
1031      *         <code>VK_UNDEFINED</code>.)
1032      */
1033     public int getKeyCode() {
1034         return keyCode;
1035     }
1036 
1037     /**
1038      * Set the keyCode value to indicate a physical key.
1039      *
1040      * @param keyCode an integer corresponding to an actual key on the keyboard.
1041      */
1042     public void setKeyCode(int keyCode) {
1043         this.keyCode = keyCode;
1044     }
1045 
1046     /**
1047      * Returns the character associated with the key in this event.
1048      * For example, the <code>KEY_TYPED</code> event for shift + "a"
1049      * returns the value for "A".
1050      * <p>
1051      * <code>KEY_PRESSED</code> and <code>KEY_RELEASED</code> events
1052      * are not intended for reporting of character input.  Therefore,
1053      * the values returned by this method are guaranteed to be
1054      * meaningful only for <code>KEY_TYPED</code> events.
1055      *
1056      * @return the Unicode character defined for this key event.
1057      *         If no valid Unicode character exists for this key event,
1058      *         <code>CHAR_UNDEFINED</code> is returned.
1059      */
1060     public char getKeyChar() {
1061         return keyChar;
1062     }
1063 
1064     /**
1065      * Set the keyChar value to indicate a logical character.
1066      *
1067      * @param keyChar a char corresponding to to the combination of keystrokes
1068      *                that make up this event.
1069      */
1070     public void setKeyChar(char keyChar) {
1071         this.keyChar = keyChar;
1072     }
1073 
1074     /**
1075      * Set the modifiers to indicate additional keys that were held down
1076      * (e.g. shift, ctrl, alt, meta) defined as part of InputEvent.
1077      * <p>
1078      * NOTE:  use of this method is not recommended, because many AWT
1079      * implementations do not recognize modifier changes.  This is
1080      * especially true for <code>KEY_TYPED</code> events where the shift
1081      * modifier is changed.
1082      *
1083      * @param modifiers an integer combination of the modifier constants.
1084      * @see InputEvent
1085      * @deprecated as of JDK1.1.4
1086      */
1087     @Deprecated
1088     public void setModifiers(int modifiers) {
1089         this.modifiers = modifiers;
1090         if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
1091             setNewModifiers();
1092         } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
1093             setOldModifiers();
1094         }
1095     }
1096 
1097     /**
1098      * Returns the location of the key that originated this key event.
1099      *
1100      * Some keys occur more than once on a keyboard, e.g. the left and
1101      * right shift keys.  Additionally, some keys occur on the numeric
1102      * keypad.  This provides a way of distinguishing such keys.
1103      *
1104      * @return the location of the key that was pressed or released.
1105      *         Always returns <code>KEY_LOCATION_UNKNOWN</code> for
1106      *         <code>KEY_TYPED</code> events.
1107      * @since 1.4
1108      */
1109     public int getKeyLocation() {
1110         return keyLocation;
1111     }
1112 
1113     /**
1114      * Returns a String describing the keyCode, such as "HOME", "F1" or "A".
1115      * These strings can be localized by changing the awt.properties file.
1116      *
1117      * @return a string containing a text description for a physical key,
1118      *         identified by its keyCode
1119      */
1120     public static String getKeyText(int keyCode) {
1121         if (keyCode >= VK_0 && keyCode <= VK_9 ||
1122             keyCode >= VK_A && keyCode <= VK_Z) {
1123             return String.valueOf((char)keyCode);
1124         }
1125 
1126         switch(keyCode) {
1127           case VK_ENTER: return Toolkit.getProperty("AWT.enter", "Enter");
1128           case VK_BACK_SPACE: return Toolkit.getProperty("AWT.backSpace", "Backspace");
1129           case VK_TAB: return Toolkit.getProperty("AWT.tab", "Tab");
1130           case VK_CANCEL: return Toolkit.getProperty("AWT.cancel", "Cancel");
1131           case VK_CLEAR: return Toolkit.getProperty("AWT.clear", "Clear");
1132           case VK_COMPOSE: return Toolkit.getProperty("AWT.compose", "Compose");
1133           case VK_PAUSE: return Toolkit.getProperty("AWT.pause", "Pause");
1134           case VK_CAPS_LOCK: return Toolkit.getProperty("AWT.capsLock", "Caps Lock");
1135           case VK_ESCAPE: return Toolkit.getProperty("AWT.escape", "Escape");
1136           case VK_SPACE: return Toolkit.getProperty("AWT.space", "Space");
1137           case VK_PAGE_UP: return Toolkit.getProperty("AWT.pgup", "Page Up");
1138           case VK_PAGE_DOWN: return Toolkit.getProperty("AWT.pgdn", "Page Down");
1139           case VK_END: return Toolkit.getProperty("AWT.end", "End");
1140           case VK_HOME: return Toolkit.getProperty("AWT.home", "Home");
1141           case VK_LEFT: return Toolkit.getProperty("AWT.left", "Left");
1142           case VK_UP: return Toolkit.getProperty("AWT.up", "Up");
1143           case VK_RIGHT: return Toolkit.getProperty("AWT.right", "Right");
1144           case VK_DOWN: return Toolkit.getProperty("AWT.down", "Down");
1145           case VK_BEGIN: return Toolkit.getProperty("AWT.begin", "Begin");
1146 
1147           // modifiers
1148           case VK_SHIFT: return Toolkit.getProperty("AWT.shift", "Shift");
1149           case VK_CONTROL: return Toolkit.getProperty("AWT.control", "Control");
1150           case VK_ALT: return Toolkit.getProperty("AWT.alt", "Alt");
1151           case VK_META: return Toolkit.getProperty("AWT.meta", "Meta");
1152           case VK_ALT_GRAPH: return Toolkit.getProperty("AWT.altGraph", "Alt Graph");
1153 
1154           // punctuation
1155           case VK_COMMA: return Toolkit.getProperty("AWT.comma", "Comma");
1156           case VK_PERIOD: return Toolkit.getProperty("AWT.period", "Period");
1157           case VK_SLASH: return Toolkit.getProperty("AWT.slash", "Slash");
1158           case VK_SEMICOLON: return Toolkit.getProperty("AWT.semicolon", "Semicolon");
1159           case VK_EQUALS: return Toolkit.getProperty("AWT.equals", "Equals");
1160           case VK_OPEN_BRACKET: return Toolkit.getProperty("AWT.openBracket", "Open Bracket");
1161           case VK_BACK_SLASH: return Toolkit.getProperty("AWT.backSlash", "Back Slash");
1162           case VK_CLOSE_BRACKET: return Toolkit.getProperty("AWT.closeBracket", "Close Bracket");
1163 
1164           // numpad numeric keys handled below
1165           case VK_MULTIPLY: return Toolkit.getProperty("AWT.multiply", "NumPad *");
1166           case VK_ADD: return Toolkit.getProperty("AWT.add", "NumPad +");
1167           case VK_SEPARATOR: return Toolkit.getProperty("AWT.separator", "NumPad ,");
1168           case VK_SUBTRACT: return Toolkit.getProperty("AWT.subtract", "NumPad -");
1169           case VK_DECIMAL: return Toolkit.getProperty("AWT.decimal", "NumPad .");
1170           case VK_DIVIDE: return Toolkit.getProperty("AWT.divide", "NumPad /");
1171           case VK_DELETE: return Toolkit.getProperty("AWT.delete", "Delete");
1172           case VK_NUM_LOCK: return Toolkit.getProperty("AWT.numLock", "Num Lock");
1173           case VK_SCROLL_LOCK: return Toolkit.getProperty("AWT.scrollLock", "Scroll Lock");
1174 
1175           case VK_WINDOWS: return Toolkit.getProperty("AWT.windows", "Windows");
1176           case VK_CONTEXT_MENU: return Toolkit.getProperty("AWT.context", "Context Menu");
1177 
1178           case VK_F1: return Toolkit.getProperty("AWT.f1", "F1");
1179           case VK_F2: return Toolkit.getProperty("AWT.f2", "F2");
1180           case VK_F3: return Toolkit.getProperty("AWT.f3", "F3");
1181           case VK_F4: return Toolkit.getProperty("AWT.f4", "F4");
1182           case VK_F5: return Toolkit.getProperty("AWT.f5", "F5");
1183           case VK_F6: return Toolkit.getProperty("AWT.f6", "F6");
1184           case VK_F7: return Toolkit.getProperty("AWT.f7", "F7");
1185           case VK_F8: return Toolkit.getProperty("AWT.f8", "F8");
1186           case VK_F9: return Toolkit.getProperty("AWT.f9", "F9");
1187           case VK_F10: return Toolkit.getProperty("AWT.f10", "F10");
1188           case VK_F11: return Toolkit.getProperty("AWT.f11", "F11");
1189           case VK_F12: return Toolkit.getProperty("AWT.f12", "F12");
1190           case VK_F13: return Toolkit.getProperty("AWT.f13", "F13");
1191           case VK_F14: return Toolkit.getProperty("AWT.f14", "F14");
1192           case VK_F15: return Toolkit.getProperty("AWT.f15", "F15");
1193           case VK_F16: return Toolkit.getProperty("AWT.f16", "F16");
1194           case VK_F17: return Toolkit.getProperty("AWT.f17", "F17");
1195           case VK_F18: return Toolkit.getProperty("AWT.f18", "F18");
1196           case VK_F19: return Toolkit.getProperty("AWT.f19", "F19");
1197           case VK_F20: return Toolkit.getProperty("AWT.f20", "F20");
1198           case VK_F21: return Toolkit.getProperty("AWT.f21", "F21");
1199           case VK_F22: return Toolkit.getProperty("AWT.f22", "F22");
1200           case VK_F23: return Toolkit.getProperty("AWT.f23", "F23");
1201           case VK_F24: return Toolkit.getProperty("AWT.f24", "F24");
1202 
1203           case VK_PRINTSCREEN: return Toolkit.getProperty("AWT.printScreen", "Print Screen");
1204           case VK_INSERT: return Toolkit.getProperty("AWT.insert", "Insert");
1205           case VK_HELP: return Toolkit.getProperty("AWT.help", "Help");
1206           case VK_BACK_QUOTE: return Toolkit.getProperty("AWT.backQuote", "Back Quote");
1207           case VK_QUOTE: return Toolkit.getProperty("AWT.quote", "Quote");
1208 
1209           case VK_KP_UP: return Toolkit.getProperty("AWT.up", "Up");
1210           case VK_KP_DOWN: return Toolkit.getProperty("AWT.down", "Down");
1211           case VK_KP_LEFT: return Toolkit.getProperty("AWT.left", "Left");
1212           case VK_KP_RIGHT: return Toolkit.getProperty("AWT.right", "Right");
1213 
1214           case VK_DEAD_GRAVE: return Toolkit.getProperty("AWT.deadGrave", "Dead Grave");
1215           case VK_DEAD_ACUTE: return Toolkit.getProperty("AWT.deadAcute", "Dead Acute");
1216           case VK_DEAD_CIRCUMFLEX: return Toolkit.getProperty("AWT.deadCircumflex", "Dead Circumflex");
1217           case VK_DEAD_TILDE: return Toolkit.getProperty("AWT.deadTilde", "Dead Tilde");
1218           case VK_DEAD_MACRON: return Toolkit.getProperty("AWT.deadMacron", "Dead Macron");
1219           case VK_DEAD_BREVE: return Toolkit.getProperty("AWT.deadBreve", "Dead Breve");
1220           case VK_DEAD_ABOVEDOT: return Toolkit.getProperty("AWT.deadAboveDot", "Dead Above Dot");
1221           case VK_DEAD_DIAERESIS: return Toolkit.getProperty("AWT.deadDiaeresis", "Dead Diaeresis");
1222           case VK_DEAD_ABOVERING: return Toolkit.getProperty("AWT.deadAboveRing", "Dead Above Ring");
1223           case VK_DEAD_DOUBLEACUTE: return Toolkit.getProperty("AWT.deadDoubleAcute", "Dead Double Acute");
1224           case VK_DEAD_CARON: return Toolkit.getProperty("AWT.deadCaron", "Dead Caron");
1225           case VK_DEAD_CEDILLA: return Toolkit.getProperty("AWT.deadCedilla", "Dead Cedilla");
1226           case VK_DEAD_OGONEK: return Toolkit.getProperty("AWT.deadOgonek", "Dead Ogonek");
1227           case VK_DEAD_IOTA: return Toolkit.getProperty("AWT.deadIota", "Dead Iota");
1228           case VK_DEAD_VOICED_SOUND: return Toolkit.getProperty("AWT.deadVoicedSound", "Dead Voiced Sound");
1229           case VK_DEAD_SEMIVOICED_SOUND: return Toolkit.getProperty("AWT.deadSemivoicedSound", "Dead Semivoiced Sound");
1230 
1231           case VK_AMPERSAND: return Toolkit.getProperty("AWT.ampersand", "Ampersand");
1232           case VK_ASTERISK: return Toolkit.getProperty("AWT.asterisk", "Asterisk");
1233           case VK_QUOTEDBL: return Toolkit.getProperty("AWT.quoteDbl", "Double Quote");
1234           case VK_LESS: return Toolkit.getProperty("AWT.Less", "Less");
1235           case VK_GREATER: return Toolkit.getProperty("AWT.greater", "Greater");
1236           case VK_BRACELEFT: return Toolkit.getProperty("AWT.braceLeft", "Left Brace");
1237           case VK_BRACERIGHT: return Toolkit.getProperty("AWT.braceRight", "Right Brace");
1238           case VK_AT: return Toolkit.getProperty("AWT.at", "At");
1239           case VK_COLON: return Toolkit.getProperty("AWT.colon", "Colon");
1240           case VK_CIRCUMFLEX: return Toolkit.getProperty("AWT.circumflex", "Circumflex");
1241           case VK_DOLLAR: return Toolkit.getProperty("AWT.dollar", "Dollar");
1242           case VK_EURO_SIGN: return Toolkit.getProperty("AWT.euro", "Euro");
1243           case VK_EXCLAMATION_MARK: return Toolkit.getProperty("AWT.exclamationMark", "Exclamation Mark");
1244           case VK_INVERTED_EXCLAMATION_MARK: return Toolkit.getProperty("AWT.invertedExclamationMark", "Inverted Exclamation Mark");
1245           case VK_LEFT_PARENTHESIS: return Toolkit.getProperty("AWT.leftParenthesis", "Left Parenthesis");
1246           case VK_NUMBER_SIGN: return Toolkit.getProperty("AWT.numberSign", "Number Sign");
1247           case VK_MINUS: return Toolkit.getProperty("AWT.minus", "Minus");
1248           case VK_PLUS: return Toolkit.getProperty("AWT.plus", "Plus");
1249           case VK_RIGHT_PARENTHESIS: return Toolkit.getProperty("AWT.rightParenthesis", "Right Parenthesis");
1250           case VK_UNDERSCORE: return Toolkit.getProperty("AWT.underscore", "Underscore");
1251 
1252           case VK_FINAL: return Toolkit.getProperty("AWT.final", "Final");
1253           case VK_CONVERT: return Toolkit.getProperty("AWT.convert", "Convert");
1254           case VK_NONCONVERT: return Toolkit.getProperty("AWT.noconvert", "No Convert");
1255           case VK_ACCEPT: return Toolkit.getProperty("AWT.accept", "Accept");
1256           case VK_MODECHANGE: return Toolkit.getProperty("AWT.modechange", "Mode Change");
1257           case VK_KANA: return Toolkit.getProperty("AWT.kana", "Kana");
1258           case VK_KANJI: return Toolkit.getProperty("AWT.kanji", "Kanji");
1259           case VK_ALPHANUMERIC: return Toolkit.getProperty("AWT.alphanumeric", "Alphanumeric");
1260           case VK_KATAKANA: return Toolkit.getProperty("AWT.katakana", "Katakana");
1261           case VK_HIRAGANA: return Toolkit.getProperty("AWT.hiragana", "Hiragana");
1262           case VK_FULL_WIDTH: return Toolkit.getProperty("AWT.fullWidth", "Full-Width");
1263           case VK_HALF_WIDTH: return Toolkit.getProperty("AWT.halfWidth", "Half-Width");
1264           case VK_ROMAN_CHARACTERS: return Toolkit.getProperty("AWT.romanCharacters", "Roman Characters");
1265           case VK_ALL_CANDIDATES: return Toolkit.getProperty("AWT.allCandidates", "All Candidates");
1266           case VK_PREVIOUS_CANDIDATE: return Toolkit.getProperty("AWT.previousCandidate", "Previous Candidate");
1267           case VK_CODE_INPUT: return Toolkit.getProperty("AWT.codeInput", "Code Input");
1268           case VK_JAPANESE_KATAKANA: return Toolkit.getProperty("AWT.japaneseKatakana", "Japanese Katakana");
1269           case VK_JAPANESE_HIRAGANA: return Toolkit.getProperty("AWT.japaneseHiragana", "Japanese Hiragana");
1270           case VK_JAPANESE_ROMAN: return Toolkit.getProperty("AWT.japaneseRoman", "Japanese Roman");
1271           case VK_KANA_LOCK: return Toolkit.getProperty("AWT.kanaLock", "Kana Lock");
1272           case VK_INPUT_METHOD_ON_OFF: return Toolkit.getProperty("AWT.inputMethodOnOff", "Input Method On/Off");
1273 
1274           case VK_AGAIN: return Toolkit.getProperty("AWT.again", "Again");
1275           case VK_UNDO: return Toolkit.getProperty("AWT.undo", "Undo");
1276           case VK_COPY: return Toolkit.getProperty("AWT.copy", "Copy");
1277           case VK_PASTE: return Toolkit.getProperty("AWT.paste", "Paste");
1278           case VK_CUT: return Toolkit.getProperty("AWT.cut", "Cut");
1279           case VK_FIND: return Toolkit.getProperty("AWT.find", "Find");
1280           case VK_PROPS: return Toolkit.getProperty("AWT.props", "Props");
1281           case VK_STOP: return Toolkit.getProperty("AWT.stop", "Stop");
1282         }
1283 
1284         if (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9) {
1285             String numpad = Toolkit.getProperty("AWT.numpad", "NumPad");
1286             char c = (char)(keyCode - VK_NUMPAD0 + '0');
1287             return numpad + "-" + c;
1288         }
1289 
1290         String unknown = Toolkit.getProperty("AWT.unknown", "Unknown");
1291         return unknown + " keyCode: 0x" + Integer.toString(keyCode, 16);
1292     }
1293 
1294     /**
1295      * Returns a <code>String</code> describing the modifier key(s),
1296      * such as "Shift", or "Ctrl+Shift".  These strings can be
1297      * localized by changing the <code>awt.properties</code> file.
1298      * <p>
1299      * Note that <code>InputEvent.ALT_MASK</code> and
1300      * <code>InputEvent.BUTTON2_MASK</code> have the same value,
1301      * so the string "Alt" is returned for both modifiers.  Likewise,
1302      * <code>InputEvent.META_MASK</code> and
1303      * <code>InputEvent.BUTTON3_MASK</code> have the same value,
1304      * so the string "Meta" is returned for both modifiers.
1305      *
1306      * @return string a text description of the combination of modifier
1307      *                keys that were held down during the event
1308      * @see InputEvent#getModifiersExText(int)
1309      */
1310     public static String getKeyModifiersText(int modifiers) {
1311         StringBuilder buf = new StringBuilder();
1312         if ((modifiers & InputEvent.META_MASK) != 0) {
1313             buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
1314             buf.append("+");
1315         }
1316         if ((modifiers & InputEvent.CTRL_MASK) != 0) {
1317             buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
1318             buf.append("+");
1319         }
1320         if ((modifiers & InputEvent.ALT_MASK) != 0) {
1321             buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
1322             buf.append("+");
1323         }
1324         if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
1325             buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
1326             buf.append("+");
1327         }
1328         if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
1329             buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
1330             buf.append("+");
1331         }
1332         if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
1333             buf.append(Toolkit.getProperty("AWT.button1", "Button1"));
1334             buf.append("+");
1335         }
1336         if (buf.length() > 0) {
1337             buf.setLength(buf.length()-1); // remove trailing '+'
1338         }
1339         return buf.toString();
1340     }
1341 
1342 
1343     /**
1344      * Returns whether the key in this event is an "action" key.
1345      * Typically an action key does not fire a unicode character and is
1346      * not a modifier key.
1347      *
1348      * @return <code>true</code> if the key is an "action" key,
1349      *         <code>false</code> otherwise
1350      */
1351     public boolean isActionKey() {
1352         switch (keyCode) {
1353           case VK_HOME:
1354           case VK_END:
1355           case VK_PAGE_UP:
1356           case VK_PAGE_DOWN:
1357           case VK_UP:
1358           case VK_DOWN:
1359           case VK_LEFT:
1360           case VK_RIGHT:
1361           case VK_BEGIN:
1362 
1363           case VK_KP_LEFT:
1364           case VK_KP_UP:
1365           case VK_KP_RIGHT:
1366           case VK_KP_DOWN:
1367 
1368           case VK_F1:
1369           case VK_F2:
1370           case VK_F3:
1371           case VK_F4:
1372           case VK_F5:
1373           case VK_F6:
1374           case VK_F7:
1375           case VK_F8:
1376           case VK_F9:
1377           case VK_F10:
1378           case VK_F11:
1379           case VK_F12:
1380           case VK_F13:
1381           case VK_F14:
1382           case VK_F15:
1383           case VK_F16:
1384           case VK_F17:
1385           case VK_F18:
1386           case VK_F19:
1387           case VK_F20:
1388           case VK_F21:
1389           case VK_F22:
1390           case VK_F23:
1391           case VK_F24:
1392           case VK_PRINTSCREEN:
1393           case VK_SCROLL_LOCK:
1394           case VK_CAPS_LOCK:
1395           case VK_NUM_LOCK:
1396           case VK_PAUSE:
1397           case VK_INSERT:
1398 
1399           case VK_FINAL:
1400           case VK_CONVERT:
1401           case VK_NONCONVERT:
1402           case VK_ACCEPT:
1403           case VK_MODECHANGE:
1404           case VK_KANA:
1405           case VK_KANJI:
1406           case VK_ALPHANUMERIC:
1407           case VK_KATAKANA:
1408           case VK_HIRAGANA:
1409           case VK_FULL_WIDTH:
1410           case VK_HALF_WIDTH:
1411           case VK_ROMAN_CHARACTERS:
1412           case VK_ALL_CANDIDATES:
1413           case VK_PREVIOUS_CANDIDATE:
1414           case VK_CODE_INPUT:
1415           case VK_JAPANESE_KATAKANA:
1416           case VK_JAPANESE_HIRAGANA:
1417           case VK_JAPANESE_ROMAN:
1418           case VK_KANA_LOCK:
1419           case VK_INPUT_METHOD_ON_OFF:
1420 
1421           case VK_AGAIN:
1422           case VK_UNDO:
1423           case VK_COPY:
1424           case VK_PASTE:
1425           case VK_CUT:
1426           case VK_FIND:
1427           case VK_PROPS:
1428           case VK_STOP:
1429 
1430           case VK_HELP:
1431           case VK_WINDOWS:
1432           case VK_CONTEXT_MENU:
1433               return true;
1434         }
1435         return false;
1436     }
1437 
1438     /**
1439      * Returns a parameter string identifying this event.
1440      * This method is useful for event logging and for debugging.
1441      *
1442      * @return a string identifying the event and its attributes
1443      */
1444     public String paramString() {
1445         StringBuilder str = new StringBuilder(100);
1446 
1447         switch (id) {
1448           case KEY_PRESSED:
1449             str.append("KEY_PRESSED");
1450             break;
1451           case KEY_RELEASED:
1452             str.append("KEY_RELEASED");
1453             break;
1454           case KEY_TYPED:
1455             str.append("KEY_TYPED");
1456             break;
1457           default:
1458             str.append("unknown type");
1459             break;
1460         }
1461 
1462         str.append(",keyCode=").append(keyCode);
1463         str.append(",keyText=").append(getKeyText(keyCode));
1464 
1465         /* Some keychars don't print well, e.g. escape, backspace,
1466          * tab, return, delete, cancel.  Get keyText for the keyCode
1467          * instead of the keyChar.
1468          */
1469         str.append(",keyChar=");
1470         switch (keyChar) {
1471           case '\b':
1472             str.append(getKeyText(VK_BACK_SPACE));
1473             break;
1474           case '\t':
1475             str.append(getKeyText(VK_TAB));
1476             break;
1477           case '\n':
1478             str.append(getKeyText(VK_ENTER));
1479             break;
1480           case '\u0018':
1481             str.append(getKeyText(VK_CANCEL));
1482             break;
1483           case '\u001b':
1484             str.append(getKeyText(VK_ESCAPE));
1485             break;
1486           case '\u007f':
1487             str.append(getKeyText(VK_DELETE));
1488             break;
1489           case CHAR_UNDEFINED:
1490             str.append(Toolkit.getProperty("AWT.undefined", "Undefined"));
1491             str.append(" keyChar");
1492             break;
1493           default:
1494             str.append("'").append(keyChar).append("'");
1495             break;
1496         }
1497 
1498         if (getModifiers() != 0) {
1499             str.append(",modifiers=").append(getKeyModifiersText(modifiers));
1500         }
1501         if (getModifiersEx() != 0) {
1502             str.append(",extModifiers=").append(getModifiersExText(modifiers));
1503         }
1504 
1505         str.append(",keyLocation=");
1506         switch (keyLocation) {
1507           case KEY_LOCATION_UNKNOWN:
1508             str.append("KEY_LOCATION_UNKNOWN");
1509             break;
1510           case KEY_LOCATION_STANDARD:
1511             str.append("KEY_LOCATION_STANDARD");
1512             break;
1513           case KEY_LOCATION_LEFT:
1514             str.append("KEY_LOCATION_LEFT");
1515             break;
1516           case KEY_LOCATION_RIGHT:
1517             str.append("KEY_LOCATION_RIGHT");
1518             break;
1519           case KEY_LOCATION_NUMPAD:
1520             str.append("KEY_LOCATION_NUMPAD");
1521             break;
1522           default:
1523             str.append("KEY_LOCATION_UNKNOWN");
1524             break;
1525         }
1526 
1527         return str.toString();
1528     }
1529 
1530     /**
1531      * Sets new modifiers by the old ones. The key modifiers
1532      * override overlaping mouse modifiers.
1533      */
1534     private void setNewModifiers() {
1535         if ((modifiers & SHIFT_MASK) != 0) {
1536             modifiers |= SHIFT_DOWN_MASK;
1537         }
1538         if ((modifiers & ALT_MASK) != 0) {
1539             modifiers |= ALT_DOWN_MASK;
1540         }
1541         if ((modifiers & CTRL_MASK) != 0) {
1542             modifiers |= CTRL_DOWN_MASK;
1543         }
1544         if ((modifiers & META_MASK) != 0) {
1545             modifiers |= META_DOWN_MASK;
1546         }
1547         if ((modifiers & ALT_GRAPH_MASK) != 0) {
1548             modifiers |= ALT_GRAPH_DOWN_MASK;
1549         }
1550         if ((modifiers & BUTTON1_MASK) != 0) {
1551             modifiers |= BUTTON1_DOWN_MASK;
1552         }
1553     }
1554 
1555     /**
1556      * Sets old modifiers by the new ones.
1557      */
1558     private void setOldModifiers() {
1559         if ((modifiers & SHIFT_DOWN_MASK) != 0) {
1560             modifiers |= SHIFT_MASK;
1561         }
1562         if ((modifiers & ALT_DOWN_MASK) != 0) {
1563             modifiers |= ALT_MASK;
1564         }
1565         if ((modifiers & CTRL_DOWN_MASK) != 0) {
1566             modifiers |= CTRL_MASK;
1567         }
1568         if ((modifiers & META_DOWN_MASK) != 0) {
1569             modifiers |= META_MASK;
1570         }
1571         if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) {
1572             modifiers |= ALT_GRAPH_MASK;
1573         }
1574         if ((modifiers & BUTTON1_DOWN_MASK) != 0) {
1575             modifiers |= BUTTON1_MASK;
1576         }
1577     }
1578 
1579     /**
1580      * Sets new modifiers by the old ones. The key modifiers
1581      * override overlaping mouse modifiers.
1582      * @serial
1583      */
1584     private void readObject(ObjectInputStream s)
1585       throws IOException, ClassNotFoundException {
1586         s.defaultReadObject();
1587         if (getModifiers() != 0 && getModifiersEx() == 0) {
1588             setNewModifiers();
1589         }
1590     }
1591 }