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