1 7 8 package java.awt.event; 9 10 import java.awt.Event ; 11 import java.awt.Component ; 12 import java.awt.GraphicsEnvironment ; 13 import java.awt.Toolkit ; 14 import java.io.IOException ; 15 import java.io.ObjectInputStream ; 16 17 112 public class KeyEvent extends InputEvent { 113 114 122 private boolean isProxyActive = false; 123 124 127 public static final int KEY_FIRST = 400; 128 129 132 public static final int KEY_LAST = 402; 133 134 141 public static final int KEY_TYPED = KEY_FIRST; 142 143 147 public static final int KEY_PRESSED = 1 + KEY_FIRST; 149 153 public static final int KEY_RELEASED = 2 + KEY_FIRST; 155 156 157 public static final int VK_ENTER = '\n'; 158 public static final int VK_BACK_SPACE = '\b'; 159 public static final int VK_TAB = '\t'; 160 public static final int VK_CANCEL = 0x03; 161 public static final int VK_CLEAR = 0x0C; 162 public static final int VK_SHIFT = 0x10; 163 public static final int VK_CONTROL = 0x11; 164 public static final int VK_ALT = 0x12; 165 public static final int VK_PAUSE = 0x13; 166 public static final int VK_CAPS_LOCK = 0x14; 167 public static final int VK_ESCAPE = 0x1B; 168 public static final int VK_SPACE = 0x20; 169 public static final int VK_PAGE_UP = 0x21; 170 public static final int VK_PAGE_DOWN = 0x22; 171 public static final int VK_END = 0x23; 172 public static final int VK_HOME = 0x24; 173 174 178 public static final int VK_LEFT = 0x25; 179 180 184 public static final int VK_UP = 0x26; 185 186 190 public static final int VK_RIGHT = 0x27; 191 192 196 public static final int VK_DOWN = 0x28; 197 198 201 public static final int VK_COMMA = 0x2C; 202 203 207 public static final int VK_MINUS = 0x2D; 208 209 212 public static final int VK_PERIOD = 0x2E; 213 214 217 public static final int VK_SLASH = 0x2F; 218 219 220 public static final int VK_0 = 0x30; 221 public static final int VK_1 = 0x31; 222 public static final int VK_2 = 0x32; 223 public static final int VK_3 = 0x33; 224 public static final int VK_4 = 0x34; 225 public static final int VK_5 = 0x35; 226 public static final int VK_6 = 0x36; 227 public static final int VK_7 = 0x37; 228 public static final int VK_8 = 0x38; 229 public static final int VK_9 = 0x39; 230 231 234 public static final int VK_SEMICOLON = 0x3B; 235 236 239 public static final int VK_EQUALS = 0x3D; 240 241 242 public static final int VK_A = 0x41; 243 public static final int VK_B = 0x42; 244 public static final int VK_C = 0x43; 245 public static final int VK_D = 0x44; 246 public static final int VK_E = 0x45; 247 public static final int VK_F = 0x46; 248 public static final int VK_G = 0x47; 249 public static final int VK_H = 0x48; 250 public static final int VK_I = 0x49; 251 public static final int VK_J = 0x4A; 252 public static final int VK_K = 0x4B; 253 public static final int VK_L = 0x4C; 254 public static final int VK_M = 0x4D; 255 public static final int VK_N = 0x4E; 256 public static final int VK_O = 0x4F; 257 public static final int VK_P = 0x50; 258 public static final int VK_Q = 0x51; 259 public static final int VK_R = 0x52; 260 public static final int VK_S = 0x53; 261 public static final int VK_T = 0x54; 262 public static final int VK_U = 0x55; 263 public static final int VK_V = 0x56; 264 public static final int VK_W = 0x57; 265 public static final int VK_X = 0x58; 266 public static final int VK_Y = 0x59; 267 public static final int VK_Z = 0x5A; 268 269 272 public static final int VK_OPEN_BRACKET = 0x5B; 273 274 277 public static final int VK_BACK_SLASH = 0x5C; 278 279 282 public static final int VK_CLOSE_BRACKET = 0x5D; 283 284 public static final int VK_NUMPAD0 = 0x60; 285 public static final int VK_NUMPAD1 = 0x61; 286 public static final int VK_NUMPAD2 = 0x62; 287 public static final int VK_NUMPAD3 = 0x63; 288 public static final int VK_NUMPAD4 = 0x64; 289 public static final int VK_NUMPAD5 = 0x65; 290 public static final int VK_NUMPAD6 = 0x66; 291 public static final int VK_NUMPAD7 = 0x67; 292 public static final int VK_NUMPAD8 = 0x68; 293 public static final int VK_NUMPAD9 = 0x69; 294 public static final int VK_MULTIPLY = 0x6A; 295 public static final int VK_ADD = 0x6B; 296 297 302 public static final int VK_SEPARATER = 0x6C; 303 304 308 public static final int VK_SEPARATOR = VK_SEPARATER; 309 310 public static final int VK_SUBTRACT = 0x6D; 311 public static final int VK_DECIMAL = 0x6E; 312 public static final int VK_DIVIDE = 0x6F; 313 public static final int VK_DELETE = 0x7F; 314 public static final int VK_NUM_LOCK = 0x90; 315 public static final int VK_SCROLL_LOCK = 0x91; 316 317 318 public static final int VK_F1 = 0x70; 319 320 321 public static final int VK_F2 = 0x71; 322 323 324 public static final int VK_F3 = 0x72; 325 326 327 public static final int VK_F4 = 0x73; 328 329 330 public static final int VK_F5 = 0x74; 331 332 333 public static final int VK_F6 = 0x75; 334 335 336 public static final int VK_F7 = 0x76; 337 338 339 public static final int VK_F8 = 0x77; 340 341 342 public static final int VK_F9 = 0x78; 343 344 345 public static final int VK_F10 = 0x79; 346 347 348 public static final int VK_F11 = 0x7A; 349 350 351 public static final int VK_F12 = 0x7B; 352 353 357 358 public static final int VK_F13 = 0xF000; 359 360 364 public static final int VK_F14 = 0xF001; 365 366 370 public static final int VK_F15 = 0xF002; 371 372 376 public static final int VK_F16 = 0xF003; 377 378 382 public static final int VK_F17 = 0xF004; 383 384 388 public static final int VK_F18 = 0xF005; 389 390 394 public static final int VK_F19 = 0xF006; 395 396 400 public static final int VK_F20 = 0xF007; 401 402 406 public static final int VK_F21 = 0xF008; 407 408 412 public static final int VK_F22 = 0xF009; 413 414 418 public static final int VK_F23 = 0xF00A; 419 420 424 public static final int VK_F24 = 0xF00B; 425 426 public static final int VK_PRINTSCREEN = 0x9A; 427 public static final int VK_INSERT = 0x9B; 428 public static final int VK_HELP = 0x9C; 429 public static final int VK_META = 0x9D; 430 431 public static final int VK_BACK_QUOTE = 0xC0; 432 public static final int VK_QUOTE = 0xDE; 433 434 439 public static final int VK_KP_UP = 0xE0; 440 441 446 public static final int VK_KP_DOWN = 0xE1; 447 448 453 public static final int VK_KP_LEFT = 0xE2; 454 455 460 public static final int VK_KP_RIGHT = 0xE3; 461 462 463 464 public static final int VK_DEAD_GRAVE = 0x80; 465 466 public static final int VK_DEAD_ACUTE = 0x81; 467 468 public static final int VK_DEAD_CIRCUMFLEX = 0x82; 469 470 public static final int VK_DEAD_TILDE = 0x83; 471 472 public static final int VK_DEAD_MACRON = 0x84; 473 474 public static final int VK_DEAD_BREVE = 0x85; 475 476 public static final int VK_DEAD_ABOVEDOT = 0x86; 477 478 public static final int VK_DEAD_DIAERESIS = 0x87; 479 480 public static final int VK_DEAD_ABOVERING = 0x88; 481 482 public static final int VK_DEAD_DOUBLEACUTE = 0x89; 483 484 public static final int VK_DEAD_CARON = 0x8a; 485 486 public static final int VK_DEAD_CEDILLA = 0x8b; 487 488 public static final int VK_DEAD_OGONEK = 0x8c; 489 490 public static final int VK_DEAD_IOTA = 0x8d; 491 492 public static final int VK_DEAD_VOICED_SOUND = 0x8e; 493 494 public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f; 495 496 497 public static final int VK_AMPERSAND = 0x96; 498 499 public static final int VK_ASTERISK = 0x97; 500 501 public static final int VK_QUOTEDBL = 0x98; 502 503 public static final int VK_LESS = 0x99; 504 505 506 public static final int VK_GREATER = 0xa0; 507 508 public static final int VK_BRACELEFT = 0xa1; 509 510 public static final int VK_BRACERIGHT = 0xa2; 511 512 516 public static final int VK_AT = 0x0200; 517 518 522 public static final int VK_COLON = 0x0201; 523 524 528 public static final int VK_CIRCUMFLEX = 0x0202; 529 530 534 public static final int VK_DOLLAR = 0x0203; 535 536 540 public static final int VK_EURO_SIGN = 0x0204; 541 542 546 public static final int VK_EXCLAMATION_MARK = 0x0205; 547 548 552 public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; 553 554 558 public static final int VK_LEFT_PARENTHESIS = 0x0207; 559 560 564 public static final int VK_NUMBER_SIGN = 0x0208; 565 566 570 public static final int VK_PLUS = 0x0209; 571 572 576 public static final int VK_RIGHT_PARENTHESIS = 0x020A; 577 578 582 public static final int VK_UNDERSCORE = 0x020B; 583 584 590 public static final int VK_WINDOWS = 0x020C; 591 592 596 public static final int VK_CONTEXT_MENU = 0x020D; 597 598 599 600 601 public static final int VK_FINAL = 0x0018; 602 603 604 605 public static final int VK_CONVERT = 0x001C; 606 607 608 609 public static final int VK_NONCONVERT = 0x001D; 610 611 612 613 public static final int VK_ACCEPT = 0x001E; 614 615 616 public static final int VK_MODECHANGE = 0x001F; 617 618 620 public static final int VK_KANA = 0x0015; 621 622 624 public static final int VK_KANJI = 0x0019; 625 626 630 631 public static final int VK_ALPHANUMERIC = 0x00F0; 632 633 637 638 public static final int VK_KATAKANA = 0x00F1; 639 640 644 645 public static final int VK_HIRAGANA = 0x00F2; 646 647 651 652 public static final int VK_FULL_WIDTH = 0x00F3; 653 654 658 659 public static final int VK_HALF_WIDTH = 0x00F4; 660 661 665 666 public static final int VK_ROMAN_CHARACTERS = 0x00F5; 667 668 672 673 public static final int VK_ALL_CANDIDATES = 0x0100; 674 675 679 680 public static final int VK_PREVIOUS_CANDIDATE = 0x0101; 681 682 686 687 public static final int VK_CODE_INPUT = 0x0102; 688 689 694 695 public static final int VK_JAPANESE_KATAKANA = 0x0103; 696 697 702 703 public static final int VK_JAPANESE_HIRAGANA = 0x0104; 704 705 710 711 public static final int VK_JAPANESE_ROMAN = 0x0105; 712 713 718 719 public static final int VK_KANA_LOCK = 0x0106; 720 721 725 726 public static final int VK_INPUT_METHOD_ON_OFF = 0x0107; 727 728 729 730 public static final int VK_CUT = 0xFFD1; 731 732 public static final int VK_COPY = 0xFFCD; 733 734 public static final int VK_PASTE = 0xFFCF; 735 736 public static final int VK_UNDO = 0xFFCB; 737 738 public static final int VK_AGAIN = 0xFFC9; 739 740 public static final int VK_FIND = 0xFFD0; 741 742 public static final int VK_PROPS = 0xFFCA; 743 744 public static final int VK_STOP = 0xFFC8; 745 746 750 public static final int VK_COMPOSE = 0xFF20; 751 752 756 public static final int VK_ALT_GRAPH = 0xFF7E; 757 758 762 public static final int VK_BEGIN = 0xFF58; 763 764 769 public static final int VK_UNDEFINED = 0x0; 770 771 775 public static final char CHAR_UNDEFINED = 0xFFFF; 776 777 784 public static final int KEY_LOCATION_UNKNOWN = 0; 785 786 794 public static final int KEY_LOCATION_STANDARD = 1; 795 796 802 public static final int KEY_LOCATION_LEFT = 2; 803 804 810 public static final int KEY_LOCATION_RIGHT = 3; 811 812 818 public static final int KEY_LOCATION_NUMPAD = 4; 819 820 831 int keyCode; 832 833 842 char keyChar; 843 844 858 int keyLocation; 859 860 private transient long rawCode = 0; 862 863 866 private static final long serialVersionUID = -2352130953028126954L; 867 868 static { 869 870 NativeLibLoader.loadLibraries(); 871 if (!GraphicsEnvironment.isHeadless()) { 872 initIDs(); 873 } 874 } 875 876 880 private static native void initIDs(); 881 882 920 private KeyEvent(Component source, int id, long when, int modifiers, 921 int keyCode, char keyChar, int keyLocation, boolean isProxyActive) { 922 this(source, id, when, modifiers, keyCode, keyChar, keyLocation); 923 this.isProxyActive = isProxyActive; 924 } 925 public KeyEvent(Component source, int id, long when, int modifiers, 926 int keyCode, char keyChar, int keyLocation) { 927 super(source, id, when, modifiers); 928 if (id == KEY_TYPED) { 929 if (keyChar == CHAR_UNDEFINED) { 930 throw new IllegalArgumentException ("invalid keyChar"); 931 } 932 if (keyCode != VK_UNDEFINED) { 933 throw new IllegalArgumentException ("invalid keyCode"); 934 } 935 if (keyLocation != KEY_LOCATION_UNKNOWN) { 936 throw new IllegalArgumentException ("invalid keyLocation"); 937 } 938 } 939 940 this.keyCode = keyCode; 941 this.keyChar = keyChar; 942 943 if ((keyLocation < KEY_LOCATION_UNKNOWN) || 944 (keyLocation > KEY_LOCATION_NUMPAD)) { 945 throw new IllegalArgumentException ("invalid keyLocation"); 946 } 947 this.keyLocation = keyLocation; 948 if ((getModifiers() != 0) && (getModifiersEx() == 0)) { 949 setNewModifiers(); 950 } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) { 951 setOldModifiers(); 952 } 953 } 954 955 984 public KeyEvent(Component source, int id, long when, int modifiers, 985 int keyCode, char keyChar) { 986 this(source, id, when, modifiers, keyCode, keyChar, 987 KEY_LOCATION_UNKNOWN); 988 } 989 990 993 @Deprecated 994 public KeyEvent(Component source, int id, long when, int modifiers, 995 int keyCode) { 996 this(source, id, when, modifiers, keyCode, (char)keyCode); 997 } 998 999 1006 public int getKeyCode() { 1007 return keyCode; 1008 } 1009 1010 1015 public void setKeyCode(int keyCode) { 1016 this.keyCode = keyCode; 1017 } 1018 1019 1033 public char getKeyChar() { 1034 return keyChar; 1035 } 1036 1037 1043 public void setKeyChar(char keyChar) { 1044 this.keyChar = keyChar; 1045 } 1046 1047 1060 @Deprecated 1061 public void setModifiers(int modifiers) { 1062 this.modifiers = modifiers; 1063 if ((getModifiers() != 0) && (getModifiersEx() == 0)) { 1064 setNewModifiers(); 1065 } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) { 1066 setOldModifiers(); 1067 } 1068 } 1069 1070 1082 public int getKeyLocation() { 1083 return keyLocation; 1084 } 1085 1086 1093 public static String getKeyText(int keyCode) { 1094 if (keyCode >= VK_0 && keyCode <= VK_9 || 1095 keyCode >= VK_A && keyCode <= VK_Z) { 1096 return String.valueOf((char)keyCode); 1097 } 1098 1099 switch(keyCode) { 1100 case VK_ENTER: return Toolkit.getProperty("AWT.enter", "Enter"); 1101 case VK_BACK_SPACE: return Toolkit.getProperty("AWT.backSpace", "Backspace"); 1102 case VK_TAB: return Toolkit.getProperty("AWT.tab", "Tab"); 1103 case VK_CANCEL: return Toolkit.getProperty("AWT.cancel", "Cancel"); 1104 case VK_CLEAR: return Toolkit.getProperty("AWT.clear", "Clear"); 1105 case VK_COMPOSE: return Toolkit.getProperty("AWT.compose", "Compose"); 1106 case VK_PAUSE: return Toolkit.getProperty("AWT.pause", "Pause"); 1107 case VK_CAPS_LOCK: return Toolkit.getProperty("AWT.capsLock", "Caps Lock"); 1108 case VK_ESCAPE: return Toolkit.getProperty("AWT.escape", "Escape"); 1109 case VK_SPACE: return Toolkit.getProperty("AWT.space", "Space"); 1110 case VK_PAGE_UP: return Toolkit.getProperty("AWT.pgup", "Page Up"); 1111 case VK_PAGE_DOWN: return Toolkit.getProperty("AWT.pgdn", "Page Down"); 1112 case VK_END: return Toolkit.getProperty("AWT.end", "End"); 1113 case VK_HOME: return Toolkit.getProperty("AWT.home", "Home"); 1114 case VK_LEFT: return Toolkit.getProperty("AWT.left", "Left"); 1115 case VK_UP: return Toolkit.getProperty("AWT.up", "Up"); 1116 case VK_RIGHT: return Toolkit.getProperty("AWT.right", "Right"); 1117 case VK_DOWN: return Toolkit.getProperty("AWT.down", "Down"); 1118 case VK_BEGIN: return Toolkit.getProperty("AWT.begin", "Begin"); 1119 1120 case VK_SHIFT: return Toolkit.getProperty("AWT.shift", "Shift"); 1122 case VK_CONTROL: return Toolkit.getProperty("AWT.control", "Control"); 1123 case VK_ALT: return Toolkit.getProperty("AWT.alt", "Alt"); 1124 case VK_META: return Toolkit.getProperty("AWT.meta", "Meta"); 1125 case VK_ALT_GRAPH: return Toolkit.getProperty("AWT.altGraph", "Alt Graph"); 1126 1127 case VK_COMMA: return Toolkit.getProperty("AWT.comma", "Comma"); 1129 case VK_PERIOD: return Toolkit.getProperty("AWT.period", "Period"); 1130 case VK_SLASH: return Toolkit.getProperty("AWT.slash", "Slash"); 1131 case VK_SEMICOLON: return Toolkit.getProperty("AWT.semicolon", "Semicolon"); 1132 case VK_EQUALS: return Toolkit.getProperty("AWT.equals", "Equals"); 1133 case VK_OPEN_BRACKET: return Toolkit.getProperty("AWT.openBracket", "Open Bracket"); 1134 case VK_BACK_SLASH: return Toolkit.getProperty("AWT.backSlash", "Back Slash"); 1135 case VK_CLOSE_BRACKET: return Toolkit.getProperty("AWT.closeBracket", "Close Bracket"); 1136 1137 case VK_MULTIPLY: return Toolkit.getProperty("AWT.multiply", "NumPad *"); 1139 case VK_ADD: return Toolkit.getProperty("AWT.add", "NumPad +"); 1140 case VK_SEPARATOR: return Toolkit.getProperty("AWT.separator", "NumPad ,"); 1141 case VK_SUBTRACT: return Toolkit.getProperty("AWT.subtract", "NumPad -"); 1142 case VK_DECIMAL: return Toolkit.getProperty("AWT.decimal", "NumPad ."); 1143 case VK_DIVIDE: return Toolkit.getProperty("AWT.divide", "NumPad /"); 1144 case VK_DELETE: return Toolkit.getProperty("AWT.delete", "Delete"); 1145 case VK_NUM_LOCK: return Toolkit.getProperty("AWT.numLock", "Num Lock"); 1146 case VK_SCROLL_LOCK: return Toolkit.getProperty("AWT.scrollLock", "Scroll Lock"); 1147 1148 case VK_WINDOWS: return Toolkit.getProperty("AWT.windows", "Windows"); 1149 case VK_CONTEXT_MENU: return Toolkit.getProperty("AWT.context", "Context Menu"); 1150 1151 case VK_F1: return Toolkit.getProperty("AWT.f1", "F1"); 1152 case VK_F2: return Toolkit.getProperty("AWT.f2", "F2"); 1153 case VK_F3: return Toolkit.getProperty("AWT.f3", "F3"); 1154 case VK_F4: return Toolkit.getProperty("AWT.f4", "F4"); 1155 case VK_F5: return Toolkit.getProperty("AWT.f5", "F5"); 1156 case VK_F6: return Toolkit.getProperty("AWT.f6", "F6"); 1157 case VK_F7: return Toolkit.getProperty("AWT.f7", "F7"); 1158 case VK_F8: return Toolkit.getProperty("AWT.f8", "F8"); 1159 case VK_F9: return Toolkit.getProperty("AWT.f9", "F9"); 1160 case VK_F10: return Toolkit.getProperty("AWT.f10", "F10"); 1161 case VK_F11: return Toolkit.getProperty("AWT.f11", "F11"); 1162 case VK_F12: return Toolkit.getProperty("AWT.f12", "F12"); 1163 case VK_F13: return Toolkit.getProperty("AWT.f13", "F13"); 1164 case VK_F14: return Toolkit.getProperty("AWT.f14", "F14"); 1165 case VK_F15: return Toolkit.getProperty("AWT.f15", "F15"); 1166 case VK_F16: return Toolkit.getProperty("AWT.f16", "F16"); 1167 case VK_F17: return Toolkit.getProperty("AWT.f17", "F17"); 1168 case VK_F18: return Toolkit.getProperty("AWT.f18", "F18"); 1169 case VK_F19: return Toolkit.getProperty("AWT.f19", "F19"); 1170 case VK_F20: return Toolkit.getProperty("AWT.f20", "F20"); 1171 case VK_F21: return Toolkit.getProperty("AWT.f21", "F21"); 1172 case VK_F22: return Toolkit.getProperty("AWT.f22", "F22"); 1173 case VK_F23: return Toolkit.getProperty("AWT.f23", "F23"); 1174 case VK_F24: return Toolkit.getProperty("AWT.f24", "F24"); 1175 1176 case VK_PRINTSCREEN: return Toolkit.getProperty("AWT.printScreen", "Print Screen"); 1177 case VK_INSERT: return Toolkit.getProperty("AWT.insert", "Insert"); 1178 case VK_HELP: return Toolkit.getProperty("AWT.help", "Help"); 1179 case VK_BACK_QUOTE: return Toolkit.getProperty("AWT.backQuote", "Back Quote"); 1180 case VK_QUOTE: return Toolkit.getProperty("AWT.quote", "Quote"); 1181 1182 case VK_KP_UP: return Toolkit.getProperty("AWT.up", "Up"); 1183 case VK_KP_DOWN: return Toolkit.getProperty("AWT.down", "Down"); 1184 case VK_KP_LEFT: return Toolkit.getProperty("AWT.left", "Left"); 1185 case VK_KP_RIGHT: return Toolkit.getProperty("AWT.right", "Right"); 1186 1187 case VK_DEAD_GRAVE: return Toolkit.getProperty("AWT.deadGrave", "Dead Grave"); 1188 case VK_DEAD_ACUTE: return Toolkit.getProperty("AWT.deadAcute", "Dead Acute"); 1189 case VK_DEAD_CIRCUMFLEX: return Toolkit.getProperty("AWT.deadCircumflex", "Dead Circumflex"); 1190 case VK_DEAD_TILDE: return Toolkit.getProperty("AWT.deadTilde", "Dead Tilde"); 1191 case VK_DEAD_MACRON: return Toolkit.getProperty("AWT.deadMacron", "Dead Macron"); 1192 case VK_DEAD_BREVE: return Toolkit.getProperty("AWT.deadBreve", "Dead Breve"); 1193 case VK_DEAD_ABOVEDOT: return Toolkit.getProperty("AWT.deadAboveDot", "Dead Above Dot"); 1194 case VK_DEAD_DIAERESIS: return Toolkit.getProperty("AWT.deadDiaeresis", "Dead Diaeresis"); 1195 case VK_DEAD_ABOVERING: return Toolkit.getProperty("AWT.deadAboveRing", "Dead Above Ring"); 1196 case VK_DEAD_DOUBLEACUTE: return Toolkit.getProperty("AWT.deadDoubleAcute", "Dead Double Acute"); 1197 case VK_DEAD_CARON: return Toolkit.getProperty("AWT.deadCaron", "Dead Caron"); 1198 case VK_DEAD_CEDILLA: return Toolkit.getProperty("AWT.deadCedilla", "Dead Cedilla"); 1199 case VK_DEAD_OGONEK: return Toolkit.getProperty("AWT.deadOgonek", "Dead Ogonek"); 1200 case VK_DEAD_IOTA: return Toolkit.getProperty("AWT.deadIota", "Dead Iota"); 1201 case VK_DEAD_VOICED_SOUND: return Toolkit.getProperty("AWT.deadVoicedSound", "Dead Voiced Sound"); 1202 case VK_DEAD_SEMIVOICED_SOUND: return Toolkit.getProperty("AWT.deadSemivoicedSound", "Dead Semivoiced Sound"); 1203 1204 case VK_AMPERSAND: return Toolkit.getProperty("AWT.ampersand", "Ampersand"); 1205 case VK_ASTERISK: return Toolkit.getProperty("AWT.asterisk", "Asterisk"); 1206 case VK_QUOTEDBL: return Toolkit.getProperty("AWT.quoteDbl", "Double Quote"); 1207 case VK_LESS: return Toolkit.getProperty("AWT.Less", "Less"); 1208 case VK_GREATER: return Toolkit.getProperty("AWT.greater", "Greater"); 1209 case VK_BRACELEFT: return Toolkit.getProperty("AWT.braceLeft", "Left Brace"); 1210 case VK_BRACERIGHT: return Toolkit.getProperty("AWT.braceRight", "Right Brace"); 1211 case VK_AT: return Toolkit.getProperty("AWT.at", "At"); 1212 case VK_COLON: return Toolkit.getProperty("AWT.colon", "Colon"); 1213 case VK_CIRCUMFLEX: return Toolkit.getProperty("AWT.circumflex", "Circumflex"); 1214 case VK_DOLLAR: return Toolkit.getProperty("AWT.dollar", "Dollar"); 1215 case VK_EURO_SIGN: return Toolkit.getProperty("AWT.euro", "Euro"); 1216 case VK_EXCLAMATION_MARK: return Toolkit.getProperty("AWT.exclamationMark", "Exclamation Mark"); 1217 case VK_INVERTED_EXCLAMATION_MARK: return Toolkit.getProperty("AWT.invertedExclamationMark", "Inverted Exclamation Mark"); 1218 case VK_LEFT_PARENTHESIS: return Toolkit.getProperty("AWT.leftParenthesis", "Left Parenthesis"); 1219 case VK_NUMBER_SIGN: return Toolkit.getProperty("AWT.numberSign", "Number Sign"); 1220 case VK_MINUS: return Toolkit.getProperty("AWT.minus", "Minus"); 1221 case VK_PLUS: return Toolkit.getProperty("AWT.plus", "Plus"); 1222 case VK_RIGHT_PARENTHESIS: return Toolkit.getProperty("AWT.rightParenthesis", "Right Parenthesis"); 1223 case VK_UNDERSCORE: return Toolkit.getProperty("AWT.underscore", "Underscore"); 1224 1225 case VK_FINAL: return Toolkit.getProperty("AWT.final", "Final"); 1226 case VK_CONVERT: return Toolkit.getProperty("AWT.convert", "Convert"); 1227 case VK_NONCONVERT: return Toolkit.getProperty("AWT.noconvert", "No Convert"); 1228 case VK_ACCEPT: return Toolkit.getProperty("AWT.accept", "Accept"); 1229 case VK_MODECHANGE: return Toolkit.getProperty("AWT.modechange", "Mode Change"); 1230 case VK_KANA: return Toolkit.getProperty("AWT.kana", "Kana"); 1231 case VK_KANJI: return Toolkit.getProperty("AWT.kanji", "Kanji"); 1232 case VK_ALPHANUMERIC: return Toolkit.getProperty("AWT.alphanumeric", "Alphanumeric"); 1233 case VK_KATAKANA: return Toolkit.getProperty("AWT.katakana", "Katakana"); 1234 case VK_HIRAGANA: return Toolkit.getProperty("AWT.hiragana", "Hiragana"); 1235 case VK_FULL_WIDTH: return Toolkit.getProperty("AWT.fullWidth", "Full-Width"); 1236 case VK_HALF_WIDTH: return Toolkit.getProperty("AWT.halfWidth", "Half-Width"); 1237 case VK_ROMAN_CHARACTERS: return Toolkit.getProperty("AWT.romanCharacters", "Roman Characters"); 1238 case VK_ALL_CANDIDATES: return Toolkit.getProperty("AWT.allCandidates", "All Candidates"); 1239 case VK_PREVIOUS_CANDIDATE: return Toolkit.getProperty("AWT.previousCandidate", "Previous Candidate"); 1240 case VK_CODE_INPUT: return Toolkit.getProperty("AWT.codeInput", "Code Input"); 1241 case VK_JAPANESE_KATAKANA: return Toolkit.getProperty("AWT.japaneseKatakana", "Japanese Katakana"); 1242 case VK_JAPANESE_HIRAGANA: return Toolkit.getProperty("AWT.japaneseHiragana", "Japanese Hiragana"); 1243 case VK_JAPANESE_ROMAN: return Toolkit.getProperty("AWT.japaneseRoman", "Japanese Roman"); 1244 case VK_KANA_LOCK: return Toolkit.getProperty("AWT.kanaLock", "Kana Lock"); 1245 case VK_INPUT_METHOD_ON_OFF: return Toolkit.getProperty("AWT.inputMethodOnOff", "Input Method On/Off"); 1246 1247 case VK_AGAIN: return Toolkit.getProperty("AWT.again", "Again"); 1248 case VK_UNDO: return Toolkit.getProperty("AWT.undo", "Undo"); 1249 case VK_COPY: return Toolkit.getProperty("AWT.copy", "Copy"); 1250 case VK_PASTE: return Toolkit.getProperty("AWT.paste", "Paste"); 1251 case VK_CUT: return Toolkit.getProperty("AWT.cut", "Cut"); 1252 case VK_FIND: return Toolkit.getProperty("AWT.find", "Find"); 1253 case VK_PROPS: return Toolkit.getProperty("AWT.props", "Props"); 1254 case VK_STOP: return Toolkit.getProperty("AWT.stop", "Stop"); 1255 } 1256 1257 if (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9) { 1258 String numpad = Toolkit.getProperty("AWT.numpad", "NumPad"); 1259 char c = (char)(keyCode - VK_NUMPAD0 + '0'); 1260 return numpad + "-" + c; 1261 } 1262 1263 String unknown = Toolkit.getProperty("AWT.unknown", "Unknown"); 1264 return unknown + " keyCode: 0x" + Integer.toString(keyCode, 16); 1265 } 1266 1267 1283 public static String getKeyModifiersText(int modifiers) { 1284 StringBuffer buf = new StringBuffer (); 1285 if ((modifiers & InputEvent.META_MASK) != 0) { 1286 buf.append(Toolkit.getProperty("AWT.meta", "Meta")); 1287 buf.append("+"); 1288 } 1289 if ((modifiers & InputEvent.CTRL_MASK) != 0) { 1290 buf.append(Toolkit.getProperty("AWT.control", "Ctrl")); 1291 buf.append("+"); 1292 } 1293 if ((modifiers & InputEvent.ALT_MASK) != 0) { 1294 buf.append(Toolkit.getProperty("AWT.alt", "Alt")); 1295 buf.append("+"); 1296 } 1297 if ((modifiers & InputEvent.SHIFT_MASK) != 0) { 1298 buf.append(Toolkit.getProperty("AWT.shift", "Shift")); 1299 buf.append("+"); 1300 } 1301 if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) { 1302 buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph")); 1303 buf.append("+"); 1304 } 1305 if ((modifiers & InputEvent.BUTTON1_MASK) != 0) { 1306 buf.append(Toolkit.getProperty("AWT.button1", "Button1")); 1307 buf.append("+"); 1308 } 1309 if (buf.length() > 0) { 1310 buf.setLength(buf.length()-1); } 1312 return buf.toString(); 1313 } 1314 1315 1316 1324 public boolean isActionKey() { 1325 switch (keyCode) { 1326 case VK_HOME: 1327 case VK_END: 1328 case VK_PAGE_UP: 1329 case VK_PAGE_DOWN: 1330 case VK_UP: 1331 case VK_DOWN: 1332 case VK_LEFT: 1333 case VK_RIGHT: 1334 case VK_BEGIN: 1335 1336 case VK_KP_LEFT: 1337 case VK_KP_UP: 1338 case VK_KP_RIGHT: 1339 case VK_KP_DOWN: 1340 1341 case VK_F1: 1342 case VK_F2: 1343 case VK_F3: 1344 case VK_F4: 1345 case VK_F5: 1346 case VK_F6: 1347 case VK_F7: 1348 case VK_F8: 1349 case VK_F9: 1350 case VK_F10: 1351 case VK_F11: 1352 case VK_F12: 1353 case VK_F13: 1354 case VK_F14: 1355 case VK_F15: 1356 case VK_F16: 1357 case VK_F17: 1358 case VK_F18: 1359 case VK_F19: 1360 case VK_F20: 1361 case VK_F21: 1362 case VK_F22: 1363 case VK_F23: 1364 case VK_F24: 1365 case VK_PRINTSCREEN: 1366 case VK_SCROLL_LOCK: 1367 case VK_CAPS_LOCK: 1368 case VK_NUM_LOCK: 1369 case VK_PAUSE: 1370 case VK_INSERT: 1371 1372 case VK_FINAL: 1373 case VK_CONVERT: 1374 case VK_NONCONVERT: 1375 case VK_ACCEPT: 1376 case VK_MODECHANGE: 1377 case VK_KANA: 1378 case VK_KANJI: 1379 case VK_ALPHANUMERIC: 1380 case VK_KATAKANA: 1381 case VK_HIRAGANA: 1382 case VK_FULL_WIDTH: 1383 case VK_HALF_WIDTH: 1384 case VK_ROMAN_CHARACTERS: 1385 case VK_ALL_CANDIDATES: 1386 case VK_PREVIOUS_CANDIDATE: 1387 case VK_CODE_INPUT: 1388 case VK_JAPANESE_KATAKANA: 1389 case VK_JAPANESE_HIRAGANA: 1390 case VK_JAPANESE_ROMAN: 1391 case VK_KANA_LOCK: 1392 case VK_INPUT_METHOD_ON_OFF: 1393 1394 case VK_AGAIN: 1395 case VK_UNDO: 1396 case VK_COPY: 1397 case VK_PASTE: 1398 case VK_CUT: 1399 case VK_FIND: 1400 case VK_PROPS: 1401 case VK_STOP: 1402 1403 case VK_HELP: 1404 case VK_WINDOWS: 1405 case VK_CONTEXT_MENU: 1406 return true; 1407 } 1408 return false; 1409 } 1410 1411 1417 public String paramString() { 1418 StringBuffer str = new StringBuffer (100); 1419 1420 switch (id) { 1421 case KEY_PRESSED: 1422 str.append("KEY_PRESSED"); 1423 break; 1424 case KEY_RELEASED: 1425 str.append("KEY_RELEASED"); 1426 break; 1427 case KEY_TYPED: 1428 str.append("KEY_TYPED"); 1429 break; 1430 default: 1431 str.append("unknown type"); 1432 break; 1433 } 1434 1435 str.append(",keyCode=").append(keyCode); 1436 str.append(",keyText=").append(getKeyText(keyCode)); 1437 1438 1442 str.append(",keyChar="); 1443 switch (keyChar) { 1444 case '\b': 1445 str.append(getKeyText(VK_BACK_SPACE)); 1446 break; 1447 case '\t': 1448 str.append(getKeyText(VK_TAB)); 1449 break; 1450 case '\n': 1451 str.append(getKeyText(VK_ENTER)); 1452 break; 1453 case '\u0018': 1454 str.append(getKeyText(VK_CANCEL)); 1455 break; 1456 case '\u001b': 1457 str.append(getKeyText(VK_ESCAPE)); 1458 break; 1459 case '\u007f': 1460 str.append(getKeyText(VK_DELETE)); 1461 break; 1462 case CHAR_UNDEFINED: 1463 str.append(Toolkit.getProperty("AWT.undefined", "Undefined")); 1464 str.append(" keyChar"); 1465 break; 1466 default: 1467 str.append("'").append(keyChar).append("'"); 1468 break; 1469 } 1470 1471 if (getModifiers() != 0) { 1472 str.append(",modifiers=").append(getKeyModifiersText(modifiers)); 1473 } 1474 if (getModifiersEx() != 0) { 1475 str.append(",extModifiers=").append(getModifiersExText(modifiers)); 1476 } 1477 1478 str.append(",keyLocation="); 1479 switch (keyLocation) { 1480 case KEY_LOCATION_UNKNOWN: 1481 str.append("KEY_LOCATION_UNKNOWN"); 1482 break; 1483 case KEY_LOCATION_STANDARD: 1484 str.append("KEY_LOCATION_STANDARD"); 1485 break; 1486 case KEY_LOCATION_LEFT: 1487 str.append("KEY_LOCATION_LEFT"); 1488 break; 1489 case KEY_LOCATION_RIGHT: 1490 str.append("KEY_LOCATION_RIGHT"); 1491 break; 1492 case KEY_LOCATION_NUMPAD: 1493 str.append("KEY_LOCATION_NUMPAD"); 1494 break; 1495 default: 1496 str.append("KEY_LOCATION_UNKNOWN"); 1497 break; 1498 } 1499 str.append(",rawCode=").append(rawCode); 1500 1501 return str.toString(); 1502 } 1503 1504 1508 private void setNewModifiers() { 1509 if ((modifiers & SHIFT_MASK) != 0) { 1510 modifiers |= SHIFT_DOWN_MASK; 1511 } 1512 if ((modifiers & ALT_MASK) != 0) { 1513 modifiers |= ALT_DOWN_MASK; 1514 } 1515 if ((modifiers & CTRL_MASK) != 0) { 1516 modifiers |= CTRL_DOWN_MASK; 1517 } 1518 if ((modifiers & META_MASK) != 0) { 1519 modifiers |= META_DOWN_MASK; 1520 } 1521 if ((modifiers & ALT_GRAPH_MASK) != 0) { 1522 modifiers |= ALT_GRAPH_DOWN_MASK; 1523 } 1524 if ((modifiers & BUTTON1_MASK) != 0) { 1525 modifiers |= BUTTON1_DOWN_MASK; 1526 } 1527 } 1528 1529 1532 private void setOldModifiers() { 1533 if ((modifiers & SHIFT_DOWN_MASK) != 0) { 1534 modifiers |= SHIFT_MASK; 1535 } 1536 if ((modifiers & ALT_DOWN_MASK) != 0) { 1537 modifiers |= ALT_MASK; 1538 } 1539 if ((modifiers & CTRL_DOWN_MASK) != 0) { 1540 modifiers |= CTRL_MASK; 1541 } 1542 if ((modifiers & META_DOWN_MASK) != 0) { 1543 modifiers |= META_MASK; 1544 } 1545 if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) { 1546 modifiers |= ALT_GRAPH_MASK; 1547 } 1548 if ((modifiers & BUTTON1_DOWN_MASK) != 0) { 1549 modifiers |= BUTTON1_MASK; 1550 } 1551 } 1552 1553 1558 private void readObject(ObjectInputStream s) 1559 throws IOException , ClassNotFoundException { 1560 s.defaultReadObject(); 1561 if (getModifiers() != 0 && getModifiersEx() == 0) { 1562 setNewModifiers(); 1563 } 1564 } 1565} 1566 1567 | Popular Tags |