Source for java.awt.event.KeyEvent

   1: /* KeyEvent.java -- event for key presses
   2:    Copyright (C) 1999, 2002, 2004, 2005  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package java.awt.event;
  40: 
  41: import gnu.java.awt.EventModifier;
  42: 
  43: import java.awt.Component;
  44: import java.io.IOException;
  45: import java.io.ObjectInputStream;
  46: 
  47: /**
  48:  * This event is generated when a key is pressed or released. There are two
  49:  * categories of key events:
  50:  *
  51:  * <p><em>"Key typed" events</em> are higher-level, and have already
  52:  * compensated for modifiers and keyboard layout to generate a single Unicode
  53:  * character. It may take several key press events to generate one key typed.
  54:  * The <code>getKeyCode</code> method will return <code>VK_UNDEFINED</code>,
  55:  * and <code>getKeyChar</code> will return a valid Unicode character or
  56:  * <code>CHAR_UNDEFINED</code>.
  57:  *
  58:  * <p><em>"Key pressed" and "key released" events</em> are lower-level, and
  59:  * are platform and keyboard dependent. They correspond to the actaul motion
  60:  * on a keyboard, and return a virtual key code which labels the key that was
  61:  * pressed. The <code>getKeyCode</code> method will return one of the
  62:  * <code>VK_*</code> constants (except VK_UNDEFINED), and the
  63:  * <code>getKeyChar</code> method is undefined.
  64:  *
  65:  * <p>Some keys do not generate key typed events, such as the F1 or HELP keys.
  66:  * Not all keyboards can generate all virtual keys, and no attempt is made to
  67:  * simulate the ones that can't be typed. Virtual keys correspond to the
  68:  * keyboard layout, so for example, VK_Q in English is VK_A in French. Also,
  69:  * there are some additional virtual keys to ease handling of actions, such
  70:  * as VK_ALL_CANDIDATES in place of ALT+VK_CONVERT. Do not rely on the value
  71:  * of the VK_* constants, except for VK_ENTER, VK_BACK_SPACE, and VK_TAB.
  72:  *
  73:  * @author Aaron M. Renn (arenn@urbanophile.com)
  74:  * @author Eric Blake (ebb9@email.byu.edu)
  75:  * @see KeyAdapter
  76:  * @see KeyListener
  77:  * @since 1.1
  78:  * @status updated to 1.4
  79:  */
  80: public class KeyEvent extends InputEvent
  81: {
  82:   /**
  83:    * Compatible with JDK 1.1+.
  84:    */
  85:   private static final long serialVersionUID = -2352130953028126954L;
  86: 
  87:   /** This is the first id in the range of event ids used by this class. */
  88:   public static final int KEY_FIRST = 400;
  89: 
  90:   /** This is the last id in the range of event ids used by this class. */
  91:   public static final int KEY_LAST = 402;
  92: 
  93:   /**
  94:    * This event id indicates a key was typed, which is a key press followed
  95:    * by a key release to generate an actual Unicode character. It may take
  96:    * several key presses to generate one key typed event, and some action
  97:    * keys have no corresponding key typed.
  98:    */
  99:   public static final int KEY_TYPED = 400;
 100: 
 101:   /** This event id indicates a key was pressed. */
 102:   public static final int KEY_PRESSED = 401;
 103: 
 104:   /** This event it indicates a key was released. */
 105:   public static final int KEY_RELEASED = 402;
 106: 
 107:   /** The virtual key Enter, which will always map to '\n'. */
 108:   public static final int VK_ENTER = '\n';
 109: 
 110:   /** The virtual key Backspace, which will always map to '\b'. */
 111:   public static final int VK_BACK_SPACE = '\b';
 112: 
 113:   /** The virtual key Tab, which will always map to '\t'. */
 114:   public static final int VK_TAB = '\t';
 115: 
 116:   /** The virtual key Cancel. */
 117:   public static final int VK_CANCEL = 3;
 118: 
 119:   /** The virtual key VK_CLEAR. */
 120:   public static final int VK_CLEAR = 12;
 121: 
 122:   /** The virtual key VK_SHIFT. */
 123:   public static final int VK_SHIFT = 16;
 124: 
 125:   /** The virtual key VK_CONTROL. */
 126:   public static final int VK_CONTROL = 17;
 127: 
 128:   /** The virtual key VK_ALT. */
 129:   public static final int VK_ALT = 18;
 130: 
 131:   /** The virtual key VK_PAUSE. */
 132:   public static final int VK_PAUSE = 19;
 133: 
 134:   /** The virtual key VK_CAPS_LOCK. */
 135:   public static final int VK_CAPS_LOCK = 20;
 136: 
 137:   /** The virtual key VK_ESCAPE. */
 138:   public static final int VK_ESCAPE = 27;
 139: 
 140:   /** The virtual key VK_SPACE. */
 141:   public static final int VK_SPACE = ' ';
 142: 
 143:   /** The virtual key VK_PAGE_UP. */
 144:   public static final int VK_PAGE_UP = 33;
 145: 
 146:   /** The virtual key VK_PAGE_DOWN. */
 147:   public static final int VK_PAGE_DOWN = 34;
 148: 
 149:   /** The virtual key VK_END. */
 150:   public static final int VK_END = 35;
 151: 
 152:   /** The virtual key VK_HOME. */
 153:   public static final int VK_HOME = 36;
 154: 
 155:   /**
 156:    * The virtual key for the non-numpad VK_LEFT.
 157:    *
 158:    * @see #VK_KP_LEFT
 159:    */
 160:   public static final int VK_LEFT = 37;
 161: 
 162:   /**
 163:    * The virtual key for the non-numpad VK_UP.
 164:    *
 165:    * @see #VK_KP_UP
 166:    */
 167:   public static final int VK_UP = 38;
 168: 
 169:   /**
 170:    * The virtual key for the non-numpad VK_RIGHT.
 171:    *
 172:    * @see #VK_KP_RIGHT
 173:    */
 174:   public static final int VK_RIGHT = 39;
 175: 
 176:   /**
 177:    * The virtual key for the non-numpad VK_DOWN.
 178:    *
 179:    * @see #VK_KP_DOWN
 180:    */
 181:   public static final int VK_DOWN = 40;
 182: 
 183:   /** The virtual key VK_COMMA. */
 184:   public static final int VK_COMMA = ',';
 185: 
 186:   /**
 187:    * The virtual key VK_MINUS.
 188:    *
 189:    * @since 1.2
 190:    */
 191:   public static final int VK_MINUS = '-';
 192: 
 193:   /** The virtual key VK_PERIOD. */
 194:   public static final int VK_PERIOD = '.';
 195: 
 196:   /** The virtual key VK_SLASH. */
 197:   public static final int VK_SLASH = '/';
 198: 
 199:   /** The virtual key VK_0. */
 200:   public static final int VK_0 = '0';
 201: 
 202:   /** The virtual key VK_1. */
 203:   public static final int VK_1 = '1';
 204: 
 205:   /** The virtual key VK_2. */
 206:   public static final int VK_2 = '2';
 207: 
 208:   /** The virtual key VK_3. */
 209:   public static final int VK_3 = '3';
 210: 
 211:   /** The virtual key VK_4. */
 212:   public static final int VK_4 = '4';
 213: 
 214:   /** The virtual key VK_5. */
 215:   public static final int VK_5 = '5';
 216: 
 217:   /** The virtual key VK_6. */
 218:   public static final int VK_6 = '6';
 219: 
 220:   /** The virtual key VK_7. */
 221:   public static final int VK_7 = '7';
 222: 
 223:   /** The virtual key VK_8. */
 224:   public static final int VK_8 = '8';
 225: 
 226:   /** The virtual key VK_9. */
 227:   public static final int VK_9 = '9';
 228: 
 229:   /** The virtual key VK_SEMICOLON. */
 230:   public static final int VK_SEMICOLON = ';';
 231: 
 232:   /** The virtual key VK_EQUALS. */
 233:   public static final int VK_EQUALS = '=';
 234: 
 235:   /** The virtual key VK_A. */
 236:   public static final int VK_A = 'A';
 237: 
 238:   /** The virtual key VK_B. */
 239:   public static final int VK_B = 'B';
 240: 
 241:   /** The virtual key VK_C. */
 242:   public static final int VK_C = 'C';
 243: 
 244:   /** The virtual key VK_D. */
 245:   public static final int VK_D = 'D';
 246: 
 247:   /** The virtual key VK_E. */
 248:   public static final int VK_E = 'E';
 249: 
 250:   /** The virtual key VK_F. */
 251:   public static final int VK_F = 'F';
 252: 
 253:   /** The virtual key VK_G. */
 254:   public static final int VK_G = 'G';
 255: 
 256:   /** The virtual key VK_H. */
 257:   public static final int VK_H = 'H';
 258: 
 259:   /** The virtual key VK_I. */
 260:   public static final int VK_I = 'I';
 261: 
 262:   /** The virtual key VK_J. */
 263:   public static final int VK_J = 'J';
 264: 
 265:   /** The virtual key VK_K. */
 266:   public static final int VK_K = 'K';
 267: 
 268:   /** The virtual key VK_L. */
 269:   public static final int VK_L = 'L';
 270: 
 271:   /** The virtual key VK_M. */
 272:   public static final int VK_M = 'M';
 273: 
 274:   /** The virtual key VK_N. */
 275:   public static final int VK_N = 'N';
 276: 
 277:   /** The virtual key VK_O. */
 278:   public static final int VK_O = 'O';
 279: 
 280:   /** The virtual key VK_P. */
 281:   public static final int VK_P = 'P';
 282: 
 283:   /** The virtual key VK_Q. */
 284:   public static final int VK_Q = 'Q';
 285: 
 286:   /** The virtual key VK_R. */
 287:   public static final int VK_R = 'R';
 288: 
 289:   /** The virtual key VK_S. */
 290:   public static final int VK_S = 'S';
 291: 
 292:   /** The virtual key VK_T. */
 293:   public static final int VK_T = 'T';
 294: 
 295:   /** The virtual key VK_U. */
 296:   public static final int VK_U = 'U';
 297: 
 298:   /** The virtual key VK_V. */
 299:   public static final int VK_V = 'V';
 300: 
 301:   /** The virtual key VK_W. */
 302:   public static final int VK_W = 'W';
 303: 
 304:   /** The virtual key VK_X. */
 305:   public static final int VK_X = 'X';
 306: 
 307:   /** The virtual key VK_Y. */
 308:   public static final int VK_Y = 'Y';
 309: 
 310:   /** The virtual key VK_Z. */
 311:   public static final int VK_Z = 'Z';
 312: 
 313:   /** The virtual key VK_OPEN_BRACKET. */
 314:   public static final int VK_OPEN_BRACKET = '[';
 315: 
 316:   /** The virtual key VK_BACK_SLASH. */
 317:   public static final int VK_BACK_SLASH = '\\';
 318: 
 319:   /** The virtual key VK_CLOSE_BRACKET. */
 320:   public static final int VK_CLOSE_BRACKET = ']';
 321: 
 322:   /** The virtual key VK_NUMPAD0. */
 323:   public static final int VK_NUMPAD0 = 96;
 324: 
 325:   /** The virtual key VK_NUMPAD1. */
 326:   public static final int VK_NUMPAD1 = 97;
 327: 
 328:   /** The virtual key VK_NUMPAD2. */
 329:   public static final int VK_NUMPAD2 = 98;
 330: 
 331:   /** The virtual key VK_NUMPAD3. */
 332:   public static final int VK_NUMPAD3 = 99;
 333: 
 334:   /** The virtual key VK_NUMPAD4. */
 335:   public static final int VK_NUMPAD4 = 100;
 336: 
 337:   /** The virtual key VK_NUMPAD5. */
 338:   public static final int VK_NUMPAD5 = 101;
 339: 
 340:   /** The virtual key VK_NUMPAD6. */
 341:   public static final int VK_NUMPAD6 = 102;
 342: 
 343:   /** The virtual key VK_NUMPAD7. */
 344:   public static final int VK_NUMPAD7 = 103;
 345: 
 346:   /** The virtual key VK_NUMPAD8. */
 347:   public static final int VK_NUMPAD8 = 104;
 348: 
 349:   /** The virtual key VK_NUMPAD9. */
 350:   public static final int VK_NUMPAD9 = 105;
 351: 
 352:   /** The virtual key VK_MULTIPLY. */
 353:   public static final int VK_MULTIPLY = 106;
 354: 
 355:   /** The virtual key VK_ADD. */
 356:   public static final int VK_ADD = 107;
 357: 
 358:   /**
 359:    * The virtual key VK_SEPARATOR, handily mispelled for those who can't
 360:    * figure it out.
 361:    *
 362:    * @deprecated use {@link #VK_SEPARATOR}
 363:    */
 364:   public static final int VK_SEPARATER = 108;
 365: 
 366:   /**
 367:    * The virtual key VK_SEPARATOR.
 368:    *
 369:    * @since 1.4
 370:    */
 371:   public static final int VK_SEPARATOR = 108;
 372: 
 373:   /** The virtual key VK_SUBTRACT. */
 374:   public static final int VK_SUBTRACT = 109;
 375: 
 376:   /** The virtual key VK_DECIMAL. */
 377:   public static final int VK_DECIMAL = 110;
 378: 
 379:   /** The virtual key VK_DIVIDE. */
 380:   public static final int VK_DIVIDE = 111;
 381: 
 382:   /** The virtual key VK_DELETE. */
 383:   public static final int VK_DELETE = 127;
 384: 
 385:   /** The virtual key VK_NUM_LOCK. */
 386:   public static final int VK_NUM_LOCK = 144;
 387: 
 388:   /** The virtual key VK_SCROLL_LOCK. */
 389:   public static final int VK_SCROLL_LOCK = 145;
 390: 
 391:   /** The virtual key VK_F1. */
 392:   public static final int VK_F1 = 112;
 393: 
 394:   /** The virtual key VK_F2. */
 395:   public static final int VK_F2 = 113;
 396: 
 397:   /** The virtual key VK_F3. */
 398:   public static final int VK_F3 = 114;
 399: 
 400:   /** The virtual key VK_F4. */
 401:   public static final int VK_F4 = 115;
 402: 
 403:   /** The virtual key VK_F5. */
 404:   public static final int VK_F5 = 116;
 405: 
 406:   /** The virtual key VK_F6. */
 407:   public static final int VK_F6 = 117;
 408: 
 409:   /** The virtual key VK_F7. */
 410:   public static final int VK_F7 = 118;
 411: 
 412:   /** The virtual key VK_F8. */
 413:   public static final int VK_F8 = 119;
 414: 
 415:   /** The virtual key VK_F9. */
 416:   public static final int VK_F9 = 120;
 417: 
 418:   /** The virtual key VK_F10. */
 419:   public static final int VK_F10 = 121;
 420: 
 421:   /** The virtual key VK_F11. */
 422:   public static final int VK_F11 = 122;
 423: 
 424:   /** The virtual key VK_F12. */
 425:   public static final int VK_F12 = 123;
 426: 
 427:   /**
 428:    * The virtual key VK_F13.
 429:    *
 430:    * @since 1.2
 431:    */
 432:   public static final int VK_F13 = 61440;
 433: 
 434:   /**
 435:    * The virtual key VK_F14.
 436:    *
 437:    * @since 1.2
 438:    */
 439:   public static final int VK_F14 = 61441;
 440: 
 441:   /**
 442:    * The virtual key VK_F15.
 443:    *
 444:    * @since 1.2
 445:    */
 446:   public static final int VK_F15 = 61442;
 447: 
 448:   /**
 449:    * The virtual key VK_F16.
 450:    *
 451:    * @since 1.2
 452:    */
 453:   public static final int VK_F16 = 61443;
 454: 
 455:   /**
 456:    * The virtual key VK_F17.
 457:    *
 458:    * @since 1.2
 459:    */
 460:   public static final int VK_F17 = 61444;
 461: 
 462:   /**
 463:    * The virtual key VK_F18.
 464:    *
 465:    * @since 1.2
 466:    */
 467:   public static final int VK_F18 = 61445;
 468: 
 469:   /**
 470:    * The virtual key VK_F19.
 471:    *
 472:    * @since 1.2
 473:    */
 474:   public static final int VK_F19 = 61446;
 475: 
 476:   /**
 477:    * The virtual key VK_F20.
 478:    *
 479:    * @since 1.2
 480:    */
 481:   public static final int VK_F20 = 61447;
 482: 
 483:   /**
 484:    * The virtual key VK_F21.
 485:    *
 486:    * @since 1.2
 487:    */
 488:   public static final int VK_F21 = 61448;
 489: 
 490:   /**
 491:    * The virtual key VK_F22.
 492:    *
 493:    * @since 1.2
 494:    */
 495:   public static final int VK_F22 = 61449;
 496: 
 497:   /**
 498:    * The virtual key VK_F23.
 499:    *
 500:    * @since 1.2
 501:    */
 502:   public static final int VK_F23 = 61450;
 503: 
 504:   /**
 505:    * The virtual key VK_F24.
 506:    *
 507:    * @since 1.2
 508:    */
 509:   public static final int VK_F24 = 61451;
 510: 
 511:   /** The virtual key VK_PRINTSCREEN. */
 512:   public static final int VK_PRINTSCREEN = 154;
 513: 
 514:   /** The virtual key VK_INSERT. */
 515:   public static final int VK_INSERT = 155;
 516: 
 517:   /** The virtual key VK_HELP. */
 518:   public static final int VK_HELP = 156;
 519: 
 520:   /** The virtual key VK_META. */
 521:   public static final int VK_META = 157;
 522: 
 523:   /** The virtual key VK_BACK_QUOTE. */
 524:   public static final int VK_BACK_QUOTE = 192;
 525: 
 526:   /** The virtual key VK_QUOTE. */
 527:   public static final int VK_QUOTE = 222;
 528: 
 529:   /**
 530:    * The virtual key for the numpad VK_KP_UP.
 531:    *
 532:    * @see #VK_UP
 533:    * @since 1.2
 534:    */
 535:   public static final int VK_KP_UP = 224;
 536: 
 537:   /**
 538:    * The virtual key for the numpad VK_KP_DOWN.
 539:    *
 540:    * @see #VK_DOWN
 541:    * @since 1.2
 542:    */
 543:   public static final int VK_KP_DOWN = 225;
 544: 
 545:   /**
 546:    * The virtual key for the numpad VK_KP_LEFT.
 547:    *
 548:    * @see #VK_LEFT
 549:    * @since 1.2
 550:    */
 551:   public static final int VK_KP_LEFT = 226;
 552: 
 553:   /**
 554:    * The virtual key for the numpad VK_KP_RIGHT.
 555:    *
 556:    * @see #VK_RIGHT
 557:    * @since 1.2
 558:    */
 559:   public static final int VK_KP_RIGHT = 227;
 560: 
 561:   /**
 562:    * The virtual key VK_DEAD_GRAVE.
 563:    *
 564:    * @since 1.2
 565:    */
 566:   public static final int VK_DEAD_GRAVE = 128;
 567: 
 568:   /**
 569:    * The virtual key VK_DEAD_ACUTE.
 570:    *
 571:    * @since 1.2
 572:    */
 573:   public static final int VK_DEAD_ACUTE = 129;
 574: 
 575:   /**
 576:    * The virtual key VK_DEAD_CIRCUMFLEX.
 577:    *
 578:    * @since 1.2
 579:    */
 580:   public static final int VK_DEAD_CIRCUMFLEX = 130;
 581: 
 582:   /**
 583:    * The virtual key VK_DEAD_TILDE.
 584:    *
 585:    * @since 1.2
 586:    */
 587:   public static final int VK_DEAD_TILDE = 131;
 588: 
 589:   /**
 590:    * The virtual key VK_DEAD_MACRON.
 591:    *
 592:    * @since 1.2
 593:    */
 594:   public static final int VK_DEAD_MACRON = 132;
 595: 
 596:   /**
 597:    * The virtual key VK_DEAD_BREVE.
 598:    *
 599:    * @since 1.2
 600:    */
 601:   public static final int VK_DEAD_BREVE = 133;
 602: 
 603:   /**
 604:    * The virtual key VK_DEAD_ABOVEDOT.
 605:    *
 606:    * @since 1.2
 607:    */
 608:   public static final int VK_DEAD_ABOVEDOT = 134;
 609: 
 610:   /**
 611:    * The virtual key VK_DEAD_DIAERESIS.
 612:    *
 613:    * @since 1.2
 614:    */
 615:   public static final int VK_DEAD_DIAERESIS = 135;
 616: 
 617:   /**
 618:    * The virtual key VK_DEAD_ABOVERING.
 619:    *
 620:    * @since 1.2
 621:    */
 622:   public static final int VK_DEAD_ABOVERING = 136;
 623: 
 624:   /**
 625:    * The virtual key VK_DEAD_DOUBLEACUTE.
 626:    *
 627:    * @since 1.2
 628:    */
 629:   public static final int VK_DEAD_DOUBLEACUTE = 137;
 630: 
 631:   /**
 632:    * The virtual key VK_DEAD_CARON.
 633:    *
 634:    * @since 1.2
 635:    */
 636:   public static final int VK_DEAD_CARON = 138;
 637: 
 638:   /**
 639:    * The virtual key VK_DEAD_CEDILLA.
 640:    *
 641:    * @since 1.2
 642:    */
 643:   public static final int VK_DEAD_CEDILLA = 139;
 644: 
 645:   /**
 646:    * The virtual key VK_DEAD_OGONEK.
 647:    *
 648:    * @since 1.2
 649:    */
 650:   public static final int VK_DEAD_OGONEK = 140;
 651: 
 652:   /**
 653:    * The virtual key VK_DEAD_IOTA.
 654:    *
 655:    * @since 1.2
 656:    */
 657:   public static final int VK_DEAD_IOTA = 141;
 658: 
 659:   /**
 660:    * The virtual key VK_DEAD_VOICED_SOUND.
 661:    *
 662:    * @since 1.2
 663:    */
 664:   public static final int VK_DEAD_VOICED_SOUND = 142;
 665: 
 666:   /**
 667:    * The virtual key VK_DEAD_SEMIVOICED_SOUND.
 668:    *
 669:    * @since 1.2
 670:    */
 671:   public static final int VK_DEAD_SEMIVOICED_SOUND = 143;
 672: 
 673:   /**
 674:    * The virtual key VK_AMPERSAND.
 675:    *
 676:    * @since 1.2
 677:    */
 678:   public static final int VK_AMPERSAND = 150;
 679: 
 680:   /**
 681:    * The virtual key VK_ASTERISK.
 682:    *
 683:    * @since 1.2
 684:    */
 685:   public static final int VK_ASTERISK = 151;
 686: 
 687:   /**
 688:    * The virtual key VK_QUOTEDBL.
 689:    *
 690:    * @since 1.2
 691:    */
 692:   public static final int VK_QUOTEDBL = 152;
 693: 
 694:   /**
 695:    * The virtual key VK_LESS.
 696:    *
 697:    * @since 1.2
 698:    */
 699:   public static final int VK_LESS = 153;
 700: 
 701:   /**
 702:    * The virtual key VK_GREATER.
 703:    *
 704:    * @since 1.2
 705:    */
 706:   public static final int VK_GREATER = 160;
 707: 
 708:   /**
 709:    * The virtual key VK_BRACELEFT.
 710:    *
 711:    * @since 1.2
 712:    */
 713:   public static final int VK_BRACELEFT = 161;
 714: 
 715:   /**
 716:    * The virtual key VK_BRACERIGHT.
 717:    *
 718:    * @since 1.2
 719:    */
 720:   public static final int VK_BRACERIGHT = 162;
 721: 
 722:   /**
 723:    * The virtual key VK_AT.
 724:    *
 725:    * @since 1.2
 726:    */
 727:   public static final int VK_AT = 512;
 728: 
 729:   /**
 730:    * The virtual key VK_COLON.
 731:    *
 732:    * @since 1.2
 733:    */
 734:   public static final int VK_COLON = 513;
 735: 
 736:   /**
 737:    * The virtual key VK_CIRCUMFLEX.
 738:    *
 739:    * @since 1.2
 740:    */
 741:   public static final int VK_CIRCUMFLEX = 514;
 742: 
 743:   /**
 744:    * The virtual key VK_DOLLAR.
 745:    *
 746:    * @since 1.2
 747:    */
 748:   public static final int VK_DOLLAR = 515;
 749: 
 750:   /**
 751:    * The virtual key VK_EURO_SIGN.
 752:    *
 753:    * @since 1.2
 754:    */
 755:   public static final int VK_EURO_SIGN = 516;
 756: 
 757:   /**
 758:    * The virtual key VK_EXCLAMATION_MARK.
 759:    *
 760:    * @since 1.2
 761:    */
 762:   public static final int VK_EXCLAMATION_MARK = 517;
 763: 
 764:   /**
 765:    * The virtual key VK_INVERTED_EXCLAMATION_MARK.
 766:    *
 767:    * @since 1.2
 768:    */
 769:   public static final int VK_INVERTED_EXCLAMATION_MARK = 518;
 770: 
 771:   /**
 772:    * The virtual key VK_LEFT_PARENTHESIS.
 773:    *
 774:    * @since 1.2
 775:    */
 776:   public static final int VK_LEFT_PARENTHESIS = 519;
 777: 
 778:   /**
 779:    * The virtual key VK_NUMBER_SIGN.
 780:    *
 781:    * @since 1.2
 782:    */
 783:   public static final int VK_NUMBER_SIGN = 520;
 784: 
 785:   /**
 786:    * The virtual key VK_PLUS.
 787:    *
 788:    * @since 1.2
 789:    */
 790:   public static final int VK_PLUS = 521;
 791: 
 792:   /**
 793:    * The virtual key VK_RIGHT_PARENTHESIS.
 794:    *
 795:    * @since 1.2
 796:    */
 797:   public static final int VK_RIGHT_PARENTHESIS = 522;
 798: 
 799:   /**
 800:    * The virtual key VK_UNDERSCORE.
 801:    *
 802:    * @since 1.2
 803:    */
 804:   public static final int VK_UNDERSCORE = 523;
 805: 
 806:   /** The virtual key VK_FINAL. */
 807:   public static final int VK_FINAL = 24;
 808: 
 809:   /** The virtual key VK_CONVERT. */
 810:   public static final int VK_CONVERT = 28;
 811: 
 812:   /** The virtual key VK_NONCONVERT. */
 813:   public static final int VK_NONCONVERT = 29;
 814: 
 815:   /** The virtual key VK_ACCEPT. */
 816:   public static final int VK_ACCEPT = 30;
 817: 
 818:   /** The virtual key VK_MODECHANGE. */
 819:   public static final int VK_MODECHANGE = 31;
 820: 
 821:   /** The virtual key VK_KANA. */
 822:   public static final int VK_KANA = 21;
 823: 
 824:   /** The virtual key VK_KANJI. */
 825:   public static final int VK_KANJI = 25;
 826: 
 827:   /**
 828:    * The virtual key VK_ALPHANUMERIC.
 829:    *
 830:    * @since 1.2
 831:    */
 832:   public static final int VK_ALPHANUMERIC = 240;
 833: 
 834:   /**
 835:    * The virtual key VK_KATAKANA.
 836:    *
 837:    * @since 1.2
 838:    */
 839:   public static final int VK_KATAKANA = 241;
 840: 
 841:   /**
 842:    * The virtual key VK_HIRAGANA.
 843:    *
 844:    * @since 1.2
 845:    */
 846:   public static final int VK_HIRAGANA = 242;
 847: 
 848:   /**
 849:    * The virtual key VK_FULL_WIDTH.
 850:    *
 851:    * @since 1.2
 852:    */
 853:   public static final int VK_FULL_WIDTH = 243;
 854: 
 855:   /**
 856:    * The virtual key VK_HALF_WIDTH.
 857:    *
 858:    * @since 1.2
 859:    */
 860:   public static final int VK_HALF_WIDTH = 244;
 861: 
 862:   /**
 863:    * The virtual key VK_ROMAN_CHARACTERS.
 864:    *
 865:    * @since 1.2
 866:    */
 867:   public static final int VK_ROMAN_CHARACTERS = 245;
 868: 
 869:   /**
 870:    * The virtual key VK_ALL_CANDIDATES.
 871:    *
 872:    * @since 1.2
 873:    */
 874:   public static final int VK_ALL_CANDIDATES = 256;
 875: 
 876:   /**
 877:    * The virtual key VK_PREVIOUS_CANDIDATE.
 878:    *
 879:    * @since 1.2
 880:    */
 881:   public static final int VK_PREVIOUS_CANDIDATE = 257;
 882: 
 883:   /**
 884:    * The virtual key VK_CODE_INPUT.
 885:    *
 886:    * @since 1.2
 887:    */
 888:   public static final int VK_CODE_INPUT = 258;
 889: 
 890:   /**
 891:    * The virtual key VK_JAPANESE_KATAKANA.
 892:    *
 893:    * @since 1.2
 894:    */
 895:   public static final int VK_JAPANESE_KATAKANA = 259;
 896: 
 897:   /**
 898:    * The virtual key VK_JAPANESE_HIRAGANA.
 899:    *
 900:    * @since 1.2
 901:    */
 902:   public static final int VK_JAPANESE_HIRAGANA = 260;
 903: 
 904:   /**
 905:    * The virtual key VK_JAPANESE_ROMAN.
 906:    *
 907:    * @since 1.2
 908:    */
 909:   public static final int VK_JAPANESE_ROMAN = 261;
 910: 
 911:   /**
 912:    * The virtual key VK_KANA_LOCK.
 913:    *
 914:    * @since 1.3
 915:    */
 916:   public static final int VK_KANA_LOCK = 262;
 917: 
 918:   /**
 919:    * The virtual key VK_INPUT_METHOD_ON_OFF.
 920:    *
 921:    * @since 1.3
 922:    */
 923:   public static final int VK_INPUT_METHOD_ON_OFF = 263;
 924: 
 925:   /**
 926:    * The virtual key VK_CUT.
 927:    *
 928:    * @since 1.2
 929:    */
 930:   public static final int VK_CUT = 65489;
 931: 
 932:   /**
 933:    * The virtual key VK_COPY.
 934:    *
 935:    * @since 1.2
 936:    */
 937:   public static final int VK_COPY = 65485;
 938: 
 939:   /**
 940:    * The virtual key VK_PASTE.
 941:    *
 942:    * @since 1.2
 943:    */
 944:   public static final int VK_PASTE = 65487;
 945: 
 946:   /**
 947:    * The virtual key VK_UNDO.
 948:    *
 949:    * @since 1.2
 950:    */
 951:   public static final int VK_UNDO = 65483;
 952: 
 953:   /**
 954:    * The virtual key VK_AGAIN.
 955:    *
 956:    * @since 1.2
 957:    */
 958:   public static final int VK_AGAIN = 65481;
 959: 
 960:   /**
 961:    * The virtual key VK_FIND.
 962:    *
 963:    * @since 1.2
 964:    */
 965:   public static final int VK_FIND = 65488;
 966: 
 967:   /**
 968:    * The virtual key VK_PROPS.
 969:    *
 970:    * @since 1.2
 971:    */
 972:   public static final int VK_PROPS = 65482;
 973: 
 974:   /**
 975:    * The virtual key VK_STOP.
 976:    *
 977:    * @since 1.2
 978:    */
 979:   public static final int VK_STOP = 65480;
 980: 
 981:   /**
 982:    * The virtual key VK_COMPOSE.
 983:    *
 984:    * @since 1.2
 985:    */
 986:   public static final int VK_COMPOSE = 65312;
 987: 
 988:   /**
 989:    * The virtual key VK_ALT_GRAPH.
 990:    *
 991:    * @since 1.2
 992:    */
 993:   public static final int VK_ALT_GRAPH = 65406;
 994: 
 995:   /**
 996:    * The 'begin' key VK_BEGIN
 997:    *
 998:    * @since 1.5
 999:    */
1000:   public static final int VK_BEGIN = 65368;
1001: 
1002:   /**
1003:    * The context-menu key VK_CONTEXT_MENU
1004:    *
1005:    * @since 1.5
1006:    */
1007:   public static final int VK_CONTEXT_MENU = 525;
1008: 
1009:   /**
1010:    * The 'Windows' key VK_WINDOWS
1011:    *
1012:    * @since 1.5
1013:    */
1014:   public static final int VK_WINDOWS = 524;
1015: 
1016:   /**
1017:    * The virtual key VK_UNDEFINED. This is used for key typed events, which
1018:    * do not have a virtual key.
1019:    */
1020:   public static final int VK_UNDEFINED = 0;
1021: 
1022:   /**
1023:    * The only char with no valid Unicode interpretation. This is used for
1024:    * key pressed and key released events which do not have a valid keyChar.
1025:    */
1026:   public static final char CHAR_UNDEFINED = '\uffff';
1027: 
1028:   /**
1029:    * Indicates unknown or irrelavent key location. This is also used for
1030:    * key typed events, which do not need a location.
1031:    *
1032:    * @since 1.4
1033:    */
1034:   public static final int KEY_LOCATION_UNKNOWN = 0;
1035: 
1036:   /**
1037:    * Indicates a standard key location, with no left/right variants and not
1038:    * on the numeric pad.
1039:    *
1040:    * @since 1.4
1041:    */
1042:   public static final int KEY_LOCATION_STANDARD = 1;
1043: 
1044:   /**
1045:    * Indicates the key is on the left side of the keyboard, such as the left
1046:    * shift.
1047:    *
1048:    * @since 1.4
1049:    */
1050:   public static final int KEY_LOCATION_LEFT = 2;
1051: 
1052:   /**
1053:    * Indicates the key is on the right side of the keyboard, such as the right
1054:    * shift.
1055:    *
1056:    * @since 1.4
1057:    */
1058:   public static final int KEY_LOCATION_RIGHT = 3;
1059: 
1060:   /**
1061:    * Indicates the key is on the numeric pad, such as the numpad 0.
1062:    *
1063:    * @since 1.4
1064:    */
1065:   public static final int KEY_LOCATION_NUMPAD = 4;
1066: 
1067:   /**
1068:    * The code assigned to the physical keyboard location (as adjusted by the
1069:    * keyboard layout). Use the symbolic VK_* names instead of numbers.
1070:    *
1071:    * @see #getKeyCode()
1072:    * @serial the VK_ code for this key
1073:   */
1074:   private int keyCode;
1075: 
1076:   /**
1077:    * The Unicode character produced by the key type event. This has no meaning
1078:    * for key pressed and key released events.
1079:    *
1080:    * @see #getKeyChar()
1081:    * @serial the Unicode value for this key
1082:    */
1083:   private char keyChar;
1084: 
1085:   /**
1086:    * The keyboard location of the key. One of {@link #KEY_LOCATION_UNKNOWN},
1087:    * {@link #KEY_LOCATION_STANDARD}, {@link #KEY_LOCATION_LEFT},
1088:    * {@link #KEY_LOCATION_RIGHT}, or {@link #KEY_LOCATION_NUMPAD}.
1089:    *
1090:    * @see #getKeyLocation()
1091:    * @serial the key location
1092:    * @since 1.4
1093:    */
1094:   private final int keyLocation;
1095: 
1096:   /**
1097:    * Stores the state of the native event dispatching system, to correctly
1098:    * dispatch in Component#dispatchEventImpl when a proxy is active.
1099:    *
1100:    * XXX Does this matter in Classpath?
1101:    *
1102:    * @serial whether the proxy is active
1103:    */
1104:   private boolean isProxyActive;
1105: 
1106: 
1107:   /**
1108:    * Initializes a new instance of <code>KeyEvent</code> with the specified
1109:    * information. Note that an invalid id leads to unspecified results.
1110:    *
1111:    * @param source the component that generated this event
1112:    * @param id the event id
1113:    * @param when the timestamp when the even occurred
1114:    * @param modifiers the modifier keys during the event, in old or new style
1115:    * @param keyCode the integer constant for the virtual key type
1116:    * @param keyChar the Unicode value of the key
1117:    * @param keyLocation the location of the key
1118:    * @throws IllegalArgumentException if source is null, if keyLocation is
1119:    *         invalid, or if (id == KEY_TYPED && (keyCode != VK_UNDEFINED
1120:    *         || keyChar == CHAR_UNDEFINED))
1121:    */
1122:   public KeyEvent(Component source, int id, long when, int modifiers,
1123:                   int keyCode, char keyChar, int keyLocation)
1124:   {
1125:     super(source, id, when, modifiers);
1126:     this.keyCode = keyCode;
1127:     this.keyChar = keyChar;
1128:     this.keyLocation = keyLocation;
1129:     if ((id == KEY_TYPED && (keyCode != VK_UNDEFINED
1130:                              || keyChar == CHAR_UNDEFINED))
1131:         || keyLocation < KEY_LOCATION_UNKNOWN
1132:         || keyLocation > KEY_LOCATION_NUMPAD)
1133:       throw new IllegalArgumentException();
1134:   }
1135: 
1136:   /**
1137:    * Initializes a new instance of <code>KeyEvent</code> with the specified
1138:    * information. Note that an invalid id leads to unspecified results.
1139:    *
1140:    * @param source the component that generated this event
1141:    * @param id the event id
1142:    * @param when the timestamp when the even occurred
1143:    * @param modifiers the modifier keys during the event, in old or new style
1144:    * @param keyCode the integer constant for the virtual key type
1145:    * @param keyChar the Unicode value of the key
1146:    * @throws IllegalArgumentException if source is null, or if
1147:    *         (id == KEY_TYPED && (keyCode != VK_UNDEFINED
1148:    *         || keyChar == CHAR_UNDEFINED))
1149:    */
1150:   public KeyEvent(Component source, int id, long when, int modifiers,
1151:                   int keyCode, char keyChar)
1152:   {
1153:     this(source, id, when, modifiers, keyCode, keyChar, KEY_LOCATION_UNKNOWN);
1154:   }
1155: 
1156:   /**
1157:    * Initializes a new instance of <code>KeyEvent</code> with the specified
1158:    * information. Note that an invalid id leads to unspecified results.
1159:    *
1160:    * @param source the component that generated this event
1161:    * @param id the event id
1162:    * @param when the timestamp when the even occurred
1163:    * @param modifiers the modifier keys during the event, in old or new style
1164:    * @param keyCode the integer constant for the virtual key type
1165:    * @throws IllegalArgumentException if source is null, or if
1166:    *         id == KEY_TYPED but keyCode != VK_UNDEFINED
1167:    *
1168:    * @deprecated
1169:    */
1170:   public KeyEvent(Component source, int id, long when, int modifiers,
1171:                   int keyCode)
1172:   {
1173:     this(source, id, when, modifiers, keyCode, '\0', KEY_LOCATION_UNKNOWN);
1174:   }
1175: 
1176:   /**
1177:    * Returns the key code for the event key.  This will be one of the
1178:    * <code>VK_*</code> constants defined in this class. If the event type is
1179:    * KEY_TYPED, the result will be VK_UNDEFINED.
1180:    *
1181:    * @return the key code for this event
1182:    */
1183:   public int getKeyCode()
1184:   {
1185:     return keyCode;
1186:   }
1187: 
1188:   /**
1189:    * Sets the key code for this event.  This must be one of the
1190:    * <code>VK_*</code> constants defined in this class.
1191:    *
1192:    * @param keyCode the new key code for this event
1193:    */
1194:   public void setKeyCode(int keyCode)
1195:   {
1196:     this.keyCode = keyCode;
1197:   }
1198: 
1199:   /**
1200:    * Returns the Unicode value for the event key.  This will be
1201:    * <code>CHAR_UNDEFINED</code> if there is no Unicode equivalent for
1202:    * this key, usually when this is a KEY_PRESSED or KEY_RELEASED event.
1203:    *
1204:    * @return the Unicode character for this event
1205:    */
1206:   public char getKeyChar()
1207:   {
1208:     return keyChar;
1209:   }
1210: 
1211:   /**
1212:    * Sets the Unicode character for this event to the specified value.
1213:    *
1214:    * @param keyChar the new Unicode character for this event
1215:    */
1216:   public void setKeyChar(char keyChar)
1217:   {
1218:     this.keyChar = keyChar;
1219:   }
1220: 
1221:   /**
1222:    * Sets the modifier keys to the specified value. This should be a union
1223:    * of the bit mask constants from <code>InputEvent</code>. The use of this
1224:    * method is not recommended, particularly for KEY_TYPED events, which do
1225:    * not check if the modifiers were changed.
1226:    *
1227:    * @param modifiers the new modifier value, in either old or new style
1228:    * @see InputEvent
1229:    *
1230:    * @deprecated
1231:    */
1232:   public void setModifiers(int modifiers)
1233:   {
1234:     this.modifiers = EventModifier.extend(modifiers);
1235:   }
1236: 
1237:   /**
1238:    * Returns the keyboard location of the key that generated this event. This
1239:    * provides a way to distinguish between keys like left and right shift
1240:    * which share a common key code. The result will be one of
1241:    * {@link #KEY_LOCATION_UNKNOWN}, {@link #KEY_LOCATION_STANDARD},
1242:    * {@link #KEY_LOCATION_LEFT}, {@link #KEY_LOCATION_RIGHT}, or
1243:    * {@link #KEY_LOCATION_NUMPAD}.
1244:    *
1245:    * @return the key location
1246:    * @since 1.4
1247:    */
1248:   public int getKeyLocation()
1249:   {
1250:     return keyLocation;
1251:   }
1252: 
1253:   /**
1254:    * Returns the text name of key code, such as "HOME", "F1", or "A".
1255:    *
1256:    * XXX Sun claims this can be localized via the awt.properties file - how
1257:    * do we implement that?
1258:    *
1259:    * @return the text name of the key code
1260:    */
1261:   public static String getKeyText(int keyCode)
1262:   {
1263:     switch (keyCode)
1264:       {
1265:       case VK_CANCEL:
1266:         return "Cancel";
1267:       case VK_BACK_SPACE:
1268:         return "Backspace";
1269:       case VK_TAB:
1270:         return "Tab";
1271:       case VK_ENTER:
1272:         return "Enter";
1273:       case VK_CLEAR:
1274:         return "Clear";
1275:       case VK_SHIFT:
1276:         return "Shift";
1277:       case VK_CONTROL:
1278:         return "Ctrl";
1279:       case VK_ALT:
1280:         return "Alt";
1281:       case VK_PAUSE:
1282:         return "Pause";
1283:       case VK_CAPS_LOCK:
1284:         return "Caps Lock";
1285:       case VK_KANA:
1286:         return "Kana";
1287:       case VK_FINAL:
1288:         return "Final";
1289:       case VK_KANJI:
1290:         return "Kanji";
1291:       case VK_ESCAPE:
1292:         return "Escape";
1293:       case VK_CONVERT:
1294:         return "Convert";
1295:       case VK_NONCONVERT:
1296:         return "No Convert";
1297:       case VK_ACCEPT:
1298:         return "Accept";
1299:       case VK_MODECHANGE:
1300:         return "Mode Change";
1301:       case VK_SPACE:
1302:         return "Space";
1303:       case VK_PAGE_UP:
1304:         return "Page Up";
1305:       case VK_PAGE_DOWN:
1306:         return "Page Down";
1307:       case VK_END:
1308:         return "End";
1309:       case VK_HOME:
1310:         return "Home";
1311:       case VK_LEFT:
1312:       case VK_KP_LEFT:
1313:         return "Left";
1314:       case VK_UP:
1315:       case VK_KP_UP:
1316:         return "Up";
1317:       case VK_RIGHT:
1318:       case VK_KP_RIGHT:
1319:         return "Right";
1320:       case VK_DOWN:
1321:       case VK_KP_DOWN:
1322:         return "Down";
1323:       case VK_MINUS:
1324:         return "Minus";
1325:       case VK_MULTIPLY:
1326:         return "NumPad *";
1327:       case VK_ADD:
1328:         return "NumPad +";
1329:       case VK_SEPARATOR:
1330:         return "NumPad ,";
1331:       case VK_SUBTRACT:
1332:         return "NumPad -";
1333:       case VK_DECIMAL:
1334:         return "NumPad .";
1335:       case VK_DIVIDE:
1336:         return "NumPad /";
1337:       case VK_DELETE:
1338:         return "Delete";
1339:       case VK_DEAD_GRAVE:
1340:         return "Dead Grave";
1341:       case VK_DEAD_ACUTE:
1342:         return "Dead Acute";
1343:       case VK_DEAD_CIRCUMFLEX:
1344:         return "Dead Circumflex";
1345:       case VK_DEAD_TILDE:
1346:         return "Dead Tilde";
1347:       case VK_DEAD_MACRON:
1348:         return "Dead Macron";
1349:       case VK_DEAD_BREVE:
1350:         return "Dead Breve";
1351:       case VK_DEAD_ABOVEDOT:
1352:         return "Dead Above Dot";
1353:       case VK_DEAD_DIAERESIS:
1354:         return "Dead Diaeresis";
1355:       case VK_DEAD_ABOVERING:
1356:         return "Dead Above Ring";
1357:       case VK_DEAD_DOUBLEACUTE:
1358:         return "Dead Double Acute";
1359:       case VK_DEAD_CARON:
1360:         return "Dead Caron";
1361:       case VK_DEAD_CEDILLA:
1362:         return "Dead Cedilla";
1363:       case VK_DEAD_OGONEK:
1364:         return "Dead Ogonek";
1365:       case VK_DEAD_IOTA:
1366:         return "Dead Iota";
1367:       case VK_DEAD_VOICED_SOUND:
1368:         return "Dead Voiced Sound";
1369:       case VK_DEAD_SEMIVOICED_SOUND:
1370:         return "Dead Semivoiced Sound";
1371:       case VK_NUM_LOCK:
1372:         return "Num Lock";
1373:       case VK_SCROLL_LOCK:
1374:         return "Scroll Lock";
1375:       case VK_AMPERSAND:
1376:         return "Ampersand";
1377:       case VK_ASTERISK:
1378:         return "Asterisk";
1379:       case VK_QUOTEDBL:
1380:         return "Double Quote";
1381:       case VK_LESS:
1382:         return "Less";
1383:       case VK_PRINTSCREEN:
1384:         return "Print Screen";
1385:       case VK_INSERT:
1386:         return "Insert";
1387:       case VK_HELP:
1388:         return "Help";
1389:       case VK_META:
1390:         return "Meta";
1391:       case VK_GREATER:
1392:         return "Greater";
1393:       case VK_BRACELEFT:
1394:         return "Left Brace";
1395:       case VK_BRACERIGHT:
1396:         return "Right Brace";
1397:       case VK_BACK_QUOTE:
1398:         return "Back Quote";
1399:       case VK_QUOTE:
1400:         return "Quote";
1401:       case VK_ALPHANUMERIC:
1402:         return "Alphanumeric";
1403:       case VK_KATAKANA:
1404:         return "Katakana";
1405:       case VK_HIRAGANA:
1406:         return "Hiragana";
1407:       case VK_FULL_WIDTH:
1408:         return "Full-Width";
1409:       case VK_HALF_WIDTH:
1410:         return "Half-Width";
1411:       case VK_ROMAN_CHARACTERS:
1412:         return "Roman Characters";
1413:       case VK_ALL_CANDIDATES:
1414:         return "All Candidates";
1415:       case VK_PREVIOUS_CANDIDATE:
1416:         return "Previous Candidate";
1417:       case VK_CODE_INPUT:
1418:         return "Code Input";
1419:       case VK_JAPANESE_KATAKANA:
1420:         return "Japanese Katakana";
1421:       case VK_JAPANESE_HIRAGANA:
1422:         return "Japanese Hiragana";
1423:       case VK_JAPANESE_ROMAN:
1424:         return "Japanese Roman";
1425:       case VK_KANA_LOCK:
1426:         return "Kana Lock";
1427:       case VK_INPUT_METHOD_ON_OFF:
1428:         return "Input Method On/Off";
1429:       case VK_AT:
1430:         return "At";
1431:       case VK_COLON:
1432:         return "Colon";
1433:       case VK_CIRCUMFLEX:
1434:         return "Circumflex";
1435:       case VK_DOLLAR:
1436:         return "Dollar";
1437:       case VK_EURO_SIGN:
1438:         return "Euro";
1439:       case VK_EXCLAMATION_MARK:
1440:         return "Exclamation Mark";
1441:       case VK_INVERTED_EXCLAMATION_MARK:
1442:         return "Inverted Exclamation Mark";
1443:       case VK_LEFT_PARENTHESIS:
1444:         return "Left Parenthesis";
1445:       case VK_NUMBER_SIGN:
1446:         return "Number Sign";
1447:       case VK_PLUS:
1448:         return "Plus";
1449:       case VK_RIGHT_PARENTHESIS:
1450:         return "Right Parenthesis";
1451:       case VK_UNDERSCORE:
1452:         return "Underscore";
1453:       case VK_COMPOSE:
1454:         return "Compose";
1455:       case VK_ALT_GRAPH:
1456:         return "Alt Graph";
1457:       case VK_STOP:
1458:         return "Stop";
1459:       case VK_AGAIN:
1460:         return "Again";
1461:       case VK_PROPS:
1462:         return "Props";
1463:       case VK_UNDO:
1464:         return "Undo";
1465:       case VK_COPY:
1466:         return "Copy";
1467:       case VK_PASTE:
1468:         return "Paste";
1469:       case VK_FIND:
1470:         return "Find";
1471:       case VK_CUT:
1472:         return "Cut";
1473:       case VK_COMMA:
1474:       case VK_PERIOD:
1475:       case VK_SLASH:
1476:       case VK_0:
1477:       case VK_1:
1478:       case VK_2:
1479:       case VK_3:
1480:       case VK_4:
1481:       case VK_5:
1482:       case VK_6:
1483:       case VK_7:
1484:       case VK_8:
1485:       case VK_9:
1486:       case VK_SEMICOLON:
1487:       case VK_EQUALS:
1488:       case VK_A:
1489:       case VK_B:
1490:       case VK_C:
1491:       case VK_D:
1492:       case VK_E:
1493:       case VK_F:
1494:       case VK_G:
1495:       case VK_H:
1496:       case VK_I:
1497:       case VK_J:
1498:       case VK_K:
1499:       case VK_L:
1500:       case VK_M:
1501:       case VK_N:
1502:       case VK_O:
1503:       case VK_P:
1504:       case VK_Q:
1505:       case VK_R:
1506:       case VK_S:
1507:       case VK_T:
1508:       case VK_U:
1509:       case VK_V:
1510:       case VK_W:
1511:       case VK_X:
1512:       case VK_Y:
1513:       case VK_Z:
1514:       case VK_OPEN_BRACKET:
1515:       case VK_BACK_SLASH:
1516:       case VK_CLOSE_BRACKET:
1517:         return "" + (char) keyCode;
1518:       case VK_NUMPAD0:
1519:       case VK_NUMPAD1:
1520:       case VK_NUMPAD2:
1521:       case VK_NUMPAD3:
1522:       case VK_NUMPAD4:
1523:       case VK_NUMPAD5:
1524:       case VK_NUMPAD6:
1525:       case VK_NUMPAD7:
1526:       case VK_NUMPAD8:
1527:       case VK_NUMPAD9:
1528:         return "NumPad-" + (keyCode - VK_NUMPAD0);
1529:       case VK_F1:
1530:       case VK_F2:
1531:       case VK_F3:
1532:       case VK_F4:
1533:       case VK_F5:
1534:       case VK_F6:
1535:       case VK_F7:
1536:       case VK_F8:
1537:       case VK_F9:
1538:       case VK_F10:
1539:       case VK_F11:
1540:       case VK_F12:
1541:         return "F" + (keyCode - (VK_F1 - 1));
1542:       case VK_F13:
1543:       case VK_F14:
1544:       case VK_F15:
1545:       case VK_F16:
1546:       case VK_F17:
1547:       case VK_F18:
1548:       case VK_F19:
1549:       case VK_F20:
1550:       case VK_F21:
1551:       case VK_F22:
1552:       case VK_F23:
1553:       case VK_F24:
1554:         return "F" + (keyCode - (VK_F13 - 13));
1555:       default:
1556:         // This is funky on negative numbers, but that's Sun's fault.
1557:         return "Unknown keyCode: 0x" + (keyCode < 0 ? "-" : "")
1558:           + Integer.toHexString(Math.abs(keyCode));
1559:       }
1560:   }
1561: 
1562:   /**
1563:    * Returns a string describing the modifiers, such as "Shift" or
1564:    * "Ctrl+Button1".
1565:    *
1566:    * XXX Sun claims this can be localized via the awt.properties file - how
1567:    * do we implement that?
1568:    *
1569:    * @param modifiers the old-style modifiers to convert to text
1570:    * @return a string representation of the modifiers in this bitmask
1571:    */
1572:   public static String getKeyModifiersText(int modifiers)
1573:   {
1574:     return getModifiersExText(EventModifier.extend(modifiers
1575:                                                    & EventModifier.OLD_MASK));
1576:   }
1577: 
1578:   /**
1579:    * Tests whether or not this key is an action key. An action key typically
1580:    * does not fire a KEY_TYPED event, and is not a modifier.
1581:    *
1582:    * @return true if this is an action key
1583:    */
1584:   public boolean isActionKey()
1585:   {
1586:     switch (keyCode)
1587:       {
1588:       case VK_PAUSE:
1589:       case VK_CAPS_LOCK:
1590:       case VK_KANA:
1591:       case VK_FINAL:
1592:       case VK_KANJI:
1593:       case VK_CONVERT:
1594:       case VK_NONCONVERT:
1595:       case VK_ACCEPT:
1596:       case VK_MODECHANGE:
1597:       case VK_PAGE_UP:
1598:       case VK_PAGE_DOWN:
1599:       case VK_END:
1600:       case VK_HOME:
1601:       case VK_LEFT:
1602:       case VK_UP:
1603:       case VK_RIGHT:
1604:       case VK_DOWN:
1605:       case VK_F1:
1606:       case VK_F2:
1607:       case VK_F3:
1608:       case VK_F4:
1609:       case VK_F5:
1610:       case VK_F6:
1611:       case VK_F7:
1612:       case VK_F8:
1613:       case VK_F9:
1614:       case VK_F10:
1615:       case VK_F11:
1616:       case VK_F12:
1617:       case VK_NUM_LOCK:
1618:       case VK_SCROLL_LOCK:
1619:       case VK_PRINTSCREEN:
1620:       case VK_INSERT:
1621:       case VK_HELP:
1622:       case VK_KP_UP:
1623:       case VK_KP_DOWN:
1624:       case VK_KP_LEFT:
1625:       case VK_KP_RIGHT:
1626:       case VK_ALPHANUMERIC:
1627:       case VK_KATAKANA:
1628:       case VK_HIRAGANA:
1629:       case VK_FULL_WIDTH:
1630:       case VK_HALF_WIDTH:
1631:       case VK_ROMAN_CHARACTERS:
1632:       case VK_ALL_CANDIDATES:
1633:       case VK_PREVIOUS_CANDIDATE:
1634:       case VK_CODE_INPUT:
1635:       case VK_JAPANESE_KATAKANA:
1636:       case VK_JAPANESE_HIRAGANA:
1637:       case VK_JAPANESE_ROMAN:
1638:       case VK_KANA_LOCK:
1639:       case VK_INPUT_METHOD_ON_OFF:
1640:       case VK_F13:
1641:       case VK_F14:
1642:       case VK_F15:
1643:       case VK_F16:
1644:       case VK_F17:
1645:       case VK_F18:
1646:       case VK_F19:
1647:       case VK_F20:
1648:       case VK_F21:
1649:       case VK_F22:
1650:       case VK_F23:
1651:       case VK_F24:
1652:       case VK_STOP:
1653:       case VK_AGAIN:
1654:       case VK_PROPS:
1655:       case VK_UNDO:
1656:       case VK_COPY:
1657:       case VK_PASTE:
1658:       case VK_FIND:
1659:       case VK_CUT:
1660:         return true;
1661:       default:
1662:         return false;
1663:       }
1664:   }
1665: 
1666:   /**
1667:    * Returns a string identifying the event.  This is formatted as the
1668:    * field name of the id type, followed by the keyCode, then the
1669:    * keyChar, modifiers (if any), extModifiers (if any), and
1670:    * keyLocation.
1671:    *
1672:    * @return a string identifying the event
1673:    */
1674:   public String paramString()
1675:   {
1676:     StringBuffer s = new StringBuffer();
1677: 
1678:     switch (id)
1679:       {
1680:       case KEY_PRESSED:
1681:         s.append("KEY_PRESSED");
1682:         break;
1683:       case KEY_RELEASED:
1684:         s.append("KEY_RELEASED");
1685:         break;
1686:       case KEY_TYPED:
1687:         s.append("KEY_TYPED");
1688:         break;
1689:       default:
1690:         s.append("unknown type");
1691:       }
1692: 
1693:     s.append(",keyCode=").append(keyCode);
1694: 
1695:     s.append(",keyText=").append(getKeyText(keyCode));
1696: 
1697:     s.append(",keyChar=");
1698:     if (isActionKey()
1699:         || keyCode == VK_SHIFT
1700:         || keyCode == VK_CONTROL
1701:         || keyCode == VK_ALT)
1702:       s.append("Undefined keyChar");
1703:     else
1704:       {
1705:         /* This output string must be selected by examining keyChar
1706:          * rather than keyCode, because key code information is not
1707:          * included in KEY_TYPED events.
1708:          */
1709:         if (keyChar == VK_BACK_SPACE
1710:             || keyChar == VK_TAB
1711:             || keyChar == VK_ENTER
1712:             || keyChar == VK_ESCAPE
1713:             || keyChar == VK_DELETE)
1714:           s.append(getKeyText(keyChar));
1715:         else
1716:           s.append("'").append(keyChar).append("'");
1717:       }
1718: 
1719:     if ((modifiers & CONVERT_MASK) != 0)
1720:       s.append(",modifiers=").append(getModifiersExText(modifiers
1721:                                                         & CONVERT_MASK));
1722:     if (modifiers != 0)
1723:       s.append(",extModifiers=").append(getModifiersExText(modifiers));
1724: 
1725:     s.append(",keyLocation=KEY_LOCATION_");
1726:     switch (keyLocation)
1727:       {
1728:       case KEY_LOCATION_UNKNOWN:
1729:         s.append("UNKNOWN");
1730:         break;
1731:       case KEY_LOCATION_STANDARD:
1732:         s.append("STANDARD");
1733:         break;
1734:       case KEY_LOCATION_LEFT:
1735:         s.append("LEFT");
1736:         break;
1737:       case KEY_LOCATION_RIGHT:
1738:         s.append("RIGHT");
1739:         break;
1740:       case KEY_LOCATION_NUMPAD:
1741:         s.append("NUMPAD");
1742:       }
1743: 
1744:     return s.toString();
1745:   }
1746: 
1747:   /**
1748:    * Reads in the object from a serial stream.
1749:    *
1750:    * @param s the stream to read from
1751:    * @throws IOException if deserialization fails
1752:    * @throws ClassNotFoundException if deserialization fails
1753:    * @serialData default, except that the modifiers are converted to new style
1754:    */
1755:   private void readObject(ObjectInputStream s)
1756:     throws IOException, ClassNotFoundException
1757:   {
1758:     s.defaultReadObject();
1759:     modifiersEx = EventModifier.extend(modifiers) & EventModifier.NEW_MASK;
1760:   }
1761: } // class KeyEvent