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