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