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