1 36 37 38 package swingwt.awt.event; 39 40 import org.eclipse.swt.SWT; 41 42 import swingwt.awt.Component; 43 44 public class KeyEvent extends InputEvent implements java.io.Serializable { 45 46 private char keyChar = ' '; 47 private int keyCode = 0; 48 public int eventID = 0; 49 50 public static final int KEY_FIRST = 400; 51 public static final int KEY_LAST = 402; 52 public static final int KEY_TYPED = KEY_FIRST; 53 public static final int KEY_PRESSED = 1 + KEY_FIRST; 54 public static final int KEY_RELEASED = 2 + KEY_FIRST; 55 56 public static final int TYPED = KEY_TYPED; 57 public static final int PRESSED = KEY_PRESSED; 58 public static final int RELEASED = KEY_RELEASED; 59 60 public static final int VK_ENTER = '\n'; 61 public static final int VK_BACK_SPACE = '\b'; 62 public static final int VK_TAB = '\t'; 63 public static final int VK_CANCEL = 0x03; 64 public static final int VK_CLEAR = 0x0C; 65 public static final int VK_SHIFT = 0x10; 66 public static final int VK_CONTROL = 0x11; 67 public static final int VK_ALT = 0x12; 68 public static final int VK_PAUSE = 0x13; 69 public static final int VK_CAPS_LOCK = 0x14; 70 public static final int VK_ESCAPE = 0x1B; 71 public static final int VK_SPACE = 0x20; 72 public static final int VK_PAGE_UP = 0x21; 73 public static final int VK_PAGE_DOWN = 0x22; 74 public static final int VK_END = 0x23; 75 public static final int VK_HOME = 0x24; 76 public static final int VK_LEFT = 0x25; 77 public static final int VK_UP = 0x26; 78 public static final int VK_RIGHT = 0x27; 79 public static final int VK_DOWN = 0x28; 80 public static final int VK_COMMA = 0x2C; 81 public static final int VK_MINUS = 0x2D; 82 public static final int VK_PERIOD = 0x2E; 83 public static final int VK_SLASH = 0x2F; 84 public static final int VK_0 = 0x30; 85 public static final int VK_1 = 0x31; 86 public static final int VK_2 = 0x32; 87 public static final int VK_3 = 0x33; 88 public static final int VK_4 = 0x34; 89 public static final int VK_5 = 0x35; 90 public static final int VK_6 = 0x36; 91 public static final int VK_7 = 0x37; 92 public static final int VK_8 = 0x38; 93 public static final int VK_9 = 0x39; 94 public static final int VK_SEMICOLON = 0x3B; 95 public static final int VK_EQUALS = 0x3D; 96 public static final int VK_A = 0x41; 97 public static final int VK_B = 0x42; 98 public static final int VK_C = 0x43; 99 public static final int VK_D = 0x44; 100 public static final int VK_E = 0x45; 101 public static final int VK_F = 0x46; 102 public static final int VK_G = 0x47; 103 public static final int VK_H = 0x48; 104 public static final int VK_I = 0x49; 105 public static final int VK_J = 0x4A; 106 public static final int VK_K = 0x4B; 107 public static final int VK_L = 0x4C; 108 public static final int VK_M = 0x4D; 109 public static final int VK_N = 0x4E; 110 public static final int VK_O = 0x4F; 111 public static final int VK_P = 0x50; 112 public static final int VK_Q = 0x51; 113 public static final int VK_R = 0x52; 114 public static final int VK_S = 0x53; 115 public static final int VK_T = 0x54; 116 public static final int VK_U = 0x55; 117 public static final int VK_V = 0x56; 118 public static final int VK_W = 0x57; 119 public static final int VK_X = 0x58; 120 public static final int VK_Y = 0x59; 121 public static final int VK_Z = 0x5A; 122 public static final int VK_OPEN_BRACKET = 0x5B; 123 public static final int VK_BACK_SLASH = 0x5C; 124 public static final int VK_CLOSE_BRACKET = 0x5D; 125 public static final int VK_NUMPAD0 = 0x60; 126 public static final int VK_NUMPAD1 = 0x61; 127 public static final int VK_NUMPAD2 = 0x62; 128 public static final int VK_NUMPAD3 = 0x63; 129 public static final int VK_NUMPAD4 = 0x64; 130 public static final int VK_NUMPAD5 = 0x65; 131 public static final int VK_NUMPAD6 = 0x66; 132 public static final int VK_NUMPAD7 = 0x67; 133 public static final int VK_NUMPAD8 = 0x68; 134 public static final int VK_NUMPAD9 = 0x69; 135 public static final int VK_MULTIPLY = 0x6A; 136 public static final int VK_ADD = 0x6B; 137 public static final int VK_SEPARATOR = 0x6C; 138 public static final int VK_SUBTRACT = 0x6D; 139 public static final int VK_DECIMAL = 0x6E; 140 public static final int VK_DIVIDE = 0x6F; 141 public static final int VK_DELETE = 0x7F; 142 public static final int VK_NUM_LOCK = 0x90; 143 public static final int VK_SCROLL_LOCK = 0x91; 144 public static final int VK_F1 = 0x70; 145 public static final int VK_F2 = 0x71; 146 public static final int VK_F3 = 0x72; 147 public static final int VK_F4 = 0x73; 148 public static final int VK_F5 = 0x74; 149 public static final int VK_F6 = 0x75; 150 public static final int VK_F7 = 0x76; 151 public static final int VK_F8 = 0x77; 152 public static final int VK_F9 = 0x78; 153 public static final int VK_F10 = 0x79; 154 public static final int VK_F11 = 0x7A; 155 public static final int VK_F12 = 0x7B; 156 public static final int VK_PRINTSCREEN = 0x9A; 157 public static final int VK_INSERT = 0x9B; 158 public static final int VK_HELP = 0x9C; 159 public static final int VK_META = 0x9D; 160 public static final int VK_BACK_QUOTE = 0xC0; 161 public static final int VK_QUOTE = 0xDE; 162 public static final int VK_KP_UP = 0xE0; 163 public static final int VK_KP_DOWN = 0xE1; 164 public static final int VK_KP_LEFT = 0xE2; 165 public static final int VK_KP_RIGHT = 0xE3; 166 public static final int VK_AMPERSAND = 0x96; 167 public static final int VK_ASTERISK = 0x97; 168 public static final int VK_QUOTEDBL = 0x98; 169 public static final int VK_LESS = 0x99; 170 public static final int VK_GREATER = 0xa0; 171 public static final int VK_BRACELEFT = 0xa1; 172 public static final int VK_BRACERIGHT = 0xa2; 173 public static final int VK_AT = 0x0200; 174 public static final int VK_COLON = 0x0201; 175 public static final int VK_CIRCUMFLEX = 0x0202; 176 public static final int VK_DOLLAR = 0x0203; 177 public static final int VK_EURO_SIGN = 0x0204; 178 public static final int VK_EXCLAMATION_MARK = 0x0205; 179 public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206; 180 public static final int VK_LEFT_PARENTHESIS = 0x0207; 181 public static final int VK_NUMBER_SIGN = 0x0208; 182 public static final int VK_PLUS = 0x0209; 183 public static final int VK_RIGHT_PARENTHESIS = 0x020A; 184 public static final int VK_UNDERSCORE = 0x020B; 185 186 public final static int SWTVK_A = 'A'; 187 public final static int SWTVK_B = 'B'; 188 public final static int SWTVK_C = 'C'; 189 public final static int SWTVK_D = 'D'; 190 public final static int SWTVK_E = 'E'; 191 public final static int SWTVK_F = 'F'; 192 public final static int SWTVK_G = 'G'; 193 public final static int SWTVK_H = 'H'; 194 public final static int SWTVK_I = 'I'; 195 public final static int SWTVK_J = 'J'; 196 public final static int SWTVK_K = 'K'; 197 public final static int SWTVK_L = 'L'; 198 public final static int SWTVK_M = 'M'; 199 public final static int SWTVK_N = 'N'; 200 public final static int SWTVK_O = 'O'; 201 public final static int SWTVK_P = 'P'; 202 public final static int SWTVK_Q = 'Q'; 203 public final static int SWTVK_R = 'R'; 204 public final static int SWTVK_S = 'S'; 205 public final static int SWTVK_T = 'T'; 206 public final static int SWTVK_U = 'U'; 207 public final static int SWTVK_V = 'V'; 208 public final static int SWTVK_W = 'W'; 209 public final static int SWTVK_X = 'X'; 210 public final static int SWTVK_Y = 'Y'; 211 public final static int SWTVK_Z = 'Z'; 212 public final static int SWTVK_SPACE = ' '; 213 public final static int SWTVK_0 = '0'; 214 public final static int SWTVK_1 = '1'; 215 public final static int SWTVK_2 = '2'; 216 public final static int SWTVK_3 = '3'; 217 public final static int SWTVK_4 = '4'; 218 public final static int SWTVK_5 = '5'; 219 public final static int SWTVK_6 = '6'; 220 public final static int SWTVK_7 = '7'; 221 public final static int SWTVK_8 = '8'; 222 public final static int SWTVK_9 = '9'; 223 public static final int SWTVK_SEMICOLON = ';'; 224 public static final int SWTVK_EQUALS = '='; 225 public static final int SWTVK_COMMA = ','; 226 public static final int SWTVK_MINUS = '-'; 227 public static final int SWTVK_PERIOD = '.'; 228 public static final int SWTVK_SLASH = '/'; 229 public static final int SWTVK_OPEN_BRACKET = '('; 230 public static final int SWTVK_BACK_SLASH = '\\'; 231 public static final int SWTVK_CLOSE_BRACKET = ')'; 232 public static final int SWTVK_UNDERSCORE = '_'; 233 public static final int SWTVK_ADD = '+'; 234 public static final int SWTVK_PLUS = '+'; 235 public static final int SWTVK_NUMBER_SIGN = '+'; 236 public static final int SWTVK_MULTIPLY = '*'; 237 public static final int SWTVK_SUBTRACT = '-'; 238 public static final int SWTVK_DECIMAL = '.'; 239 public static final int SWTVK_DIVIDE = '.'; 240 public static final int SWTVK_BACK_QUOTE = '`'; 241 public static final int SWTVK_QUOTE = '\''; 242 public static final int SWTVK_AMPERSAND = '&'; 243 public static final int SWTVK_ASTERISK = '*'; 244 public static final int SWTVK_QUOTEDBL = '"'; 245 public static final int SWTVK_LESS = '<'; 246 public static final int SWTVK_GREATER = '>'; 247 public static final int SWTVK_BRACELEFT = '{'; 248 public static final int SWTVK_BRACERIGHT = '}'; 249 public static final int SWTVK_AT = '@'; 250 public static final int SWTVK_CIRCUMFLEX = '~'; 251 public static final int SWTVK_DOLLAR = '$'; 252 public static final int SWTVK_EURO_SIGN = '$'; 253 public static final int SWTVK_EXCLAMATION_MARK = '!'; 254 public static final int SWTVK_INVERTED_EXCLAMATION_MARK = '!'; 255 public static final int SWTVK_LEFT_PARENTHESIS = '('; 256 public static final int SWTVK_RIGHT_PARENTHESIS = ')'; 257 public static final int SWTVK_COLON = ':'; 258 public static final int SWTVK_TAB = '\t'; 259 public static final int SWTVK_F1 = SWT.F1; 260 public static final int SWTVK_F2 = SWT.F2; 261 public static final int SWTVK_F3 = SWT.F3; 262 public static final int SWTVK_F4 = SWT.F4; 263 public static final int SWTVK_F5 = SWT.F5; 264 public static final int SWTVK_F6 = SWT.F6; 265 public static final int SWTVK_F7 = SWT.F7; 266 public static final int SWTVK_F8 = SWT.F8; 267 public static final int SWTVK_F9 = SWT.F9; 268 public static final int SWTVK_F10 = SWT.F10; 269 public static final int SWTVK_F11 = SWT.F11; 270 public static final int SWTVK_F12 = SWT.F12; 271 public static final int SWTVK_ENTER = SWT.CR; 272 public static final int SWTVK_BACK_SPACE = 8; 273 public static final int SWTVK_DELETE = SWT.DEL; 274 public static final int SWTVK_ESCAPE = SWT.ESC; 275 276 public static final int SWTVK_LEFT = SWT.LEFT; 277 public static final int SWTVK_KP_LEFT = SWT.LEFT; 278 public static final int SWTVK_RIGHT = SWT.RIGHT; 279 public static final int SWTVK_KP_RIGHT = SWT.RIGHT; 280 public static final int SWTVK_UP = SWT.UP; 281 public static final int SWTVK_KP_UP = SWT.UP; 282 public static final int SWTVK_DOWN = SWT.DOWN; 283 284 public static final int SWTVK_KP_DOWN = SWT.DOWN; 285 public static final int SWTVK_HOME = SWT.HOME; 286 public static final int SWTVK_END = SWT.END; 287 public static final int SWTVK_PAGE_UP = SWT.PAGE_UP; 288 public static final int SWTVK_PAGE_DOWN = SWT.PAGE_DOWN; 289 public static final int SWTVK_INSERT = SWT.INSERT; 290 public static final int SWTVK_SHIFT = SWT.SHIFT; 291 public static final int SWTVK_CONTROL = SWT.CONTROL; 292 public static final int SWTVK_ALT = SWT.ALT; 293 public static final int SWTVK_META = SWT.ALT; 294 public static final int SWTVK_CANCEL = SWT.CANCEL; 295 public static final int SWTVK_CLEAR = SWT.NONE; 296 public static final int SWTVK_PAUSE = SWT.PAUSE; 297 public static final int SWTVK_CAPS_LOCK = SWT.CAPS_LOCK; 298 public static final int SWTVK_SEPARATOR = SWT.SEPARATOR; 299 public static final int SWTVK_NUM_LOCK = SWT.NUM_LOCK; 300 public static final int SWTVK_SCROLL_LOCK = SWT.SCROLL_LOCK; 301 public static final int SWTVK_PRINTSCREEN = SWT.PRINT_SCREEN; 302 public static final int SWTVK_HELP = SWT.HELP; 303 304 305 308 private static int[] translationMap = new int[] { 309 VK_ENTER, SWTVK_ENTER, 310 VK_BACK_SPACE, SWTVK_BACK_SPACE, 311 VK_TAB, SWTVK_TAB, 312 VK_CANCEL, SWTVK_CANCEL, 313 VK_CLEAR, SWTVK_CLEAR, 314 VK_SHIFT, SWTVK_SHIFT, 315 VK_CONTROL, SWTVK_CONTROL, 316 VK_ALT, SWTVK_ALT, 317 VK_PAUSE, SWTVK_PAUSE, 318 VK_CAPS_LOCK, SWTVK_CAPS_LOCK, 319 VK_ESCAPE, SWTVK_ESCAPE, 320 VK_SPACE, SWTVK_SPACE, 321 VK_PAGE_UP, SWTVK_PAGE_UP, 322 VK_PAGE_DOWN, SWTVK_PAGE_DOWN, 323 VK_END, SWTVK_END, 324 VK_HOME, SWTVK_HOME, 325 VK_LEFT, SWTVK_LEFT, 326 VK_UP, SWTVK_UP, 327 VK_RIGHT, SWTVK_RIGHT, 328 VK_DOWN, SWTVK_DOWN, 329 VK_COMMA, SWTVK_COMMA, 330 VK_MINUS, SWTVK_MINUS, 331 VK_PERIOD, SWTVK_PERIOD, 332 VK_SLASH, SWTVK_SLASH, 333 VK_0, SWTVK_0, 334 VK_1, SWTVK_1, 335 VK_2, SWTVK_2, 336 VK_3, SWTVK_3, 337 VK_4, SWTVK_4, 338 VK_5, SWTVK_5, 339 VK_6, SWTVK_6, 340 VK_7, SWTVK_7, 341 VK_8, SWTVK_8, 342 VK_9, SWTVK_9, 343 VK_SEMICOLON, SWTVK_SEMICOLON, 344 VK_EQUALS, SWTVK_EQUALS, 345 VK_A, SWTVK_A, 346 VK_B, SWTVK_B, 347 VK_C, SWTVK_C, 348 VK_D, SWTVK_D, 349 VK_E, SWTVK_E, 350 VK_F, SWTVK_F, 351 VK_G, SWTVK_G, 352 VK_H, SWTVK_H, 353 VK_I, SWTVK_I, 354 VK_J, SWTVK_J, 355 VK_K, SWTVK_K, 356 VK_L, SWTVK_L, 357 VK_M, SWTVK_M, 358 VK_N, SWTVK_N, 359 VK_O, SWTVK_O, 360 VK_P, SWTVK_P, 361 VK_Q, SWTVK_Q, 362 VK_R, SWTVK_R, 363 VK_S, SWTVK_S, 364 VK_T, SWTVK_T, 365 VK_U, SWTVK_U, 366 VK_V, SWTVK_V, 367 VK_W, SWTVK_W, 368 VK_X, SWTVK_X, 369 VK_Y, SWTVK_Y, 370 VK_Z, SWTVK_Z, 371 VK_OPEN_BRACKET, SWTVK_OPEN_BRACKET, 372 VK_BACK_SLASH, SWTVK_BACK_SLASH, 373 VK_CLOSE_BRACKET, SWTVK_CLOSE_BRACKET, 374 VK_NUMPAD0, SWTVK_0, 375 VK_NUMPAD1, SWTVK_1, 376 VK_NUMPAD2, SWTVK_2, 377 VK_NUMPAD3, SWTVK_3, 378 VK_NUMPAD4, SWTVK_4, 379 VK_NUMPAD5, SWTVK_5, 380 VK_NUMPAD6, SWTVK_6, 381 VK_NUMPAD7, SWTVK_7, 382 VK_NUMPAD8, SWTVK_8, 383 VK_NUMPAD9, SWTVK_9, 384 VK_MULTIPLY, SWTVK_MULTIPLY, 385 VK_ADD, SWTVK_ADD, 386 VK_SEPARATOR, SWTVK_SEPARATOR, 387 VK_SUBTRACT, SWTVK_SUBTRACT, 388 VK_DECIMAL, SWTVK_DECIMAL, 389 VK_DIVIDE, SWTVK_DIVIDE, 390 VK_DELETE, SWTVK_DELETE, 391 VK_NUM_LOCK, SWTVK_NUM_LOCK, 392 VK_SCROLL_LOCK, SWTVK_SCROLL_LOCK, 393 VK_F1, SWTVK_F1, 394 VK_F2, SWTVK_F2, 395 VK_F3, SWTVK_F3, 396 VK_F4, SWTVK_F4, 397 VK_F5, SWTVK_F5, 398 VK_F6, SWTVK_F6, 399 VK_F7, SWTVK_F7, 400 VK_F8, SWTVK_F8, 401 VK_F9, SWTVK_F9, 402 VK_F10, SWTVK_F10, 403 VK_F11, SWTVK_F11, 404 VK_F12, SWTVK_F12, 405 VK_PRINTSCREEN, SWTVK_PRINTSCREEN, 406 VK_INSERT, SWTVK_INSERT, 407 VK_HELP, SWTVK_HELP, 408 VK_META, SWTVK_META, 409 VK_BACK_QUOTE, SWTVK_BACK_QUOTE, 410 VK_QUOTE, SWTVK_QUOTE, 411 VK_KP_UP, SWTVK_UP, 412 VK_KP_DOWN, SWTVK_DOWN, 413 VK_KP_LEFT, SWTVK_LEFT, 414 VK_KP_RIGHT, SWTVK_RIGHT, 415 VK_AMPERSAND, SWTVK_AMPERSAND, 416 VK_ASTERISK, SWTVK_ASTERISK, 417 VK_QUOTEDBL, SWTVK_QUOTEDBL, 418 VK_LESS, SWTVK_LESS, 419 VK_GREATER, SWTVK_GREATER, 420 VK_BRACELEFT, SWTVK_BRACELEFT, 421 VK_BRACERIGHT, SWTVK_BRACERIGHT, 422 VK_AT, SWTVK_AT, 423 VK_COLON, SWTVK_COLON, 424 VK_CIRCUMFLEX, SWTVK_CIRCUMFLEX, 425 VK_DOLLAR, SWTVK_DOLLAR, 426 VK_EURO_SIGN, SWTVK_EURO_SIGN, 427 VK_EXCLAMATION_MARK, SWTVK_EXCLAMATION_MARK, 428 VK_INVERTED_EXCLAMATION_MARK, SWTVK_INVERTED_EXCLAMATION_MARK, 429 VK_LEFT_PARENTHESIS, SWTVK_LEFT_PARENTHESIS, 430 VK_NUMBER_SIGN, SWTVK_NUMBER_SIGN, 431 VK_PLUS, SWTVK_PLUS, 432 VK_RIGHT_PARENTHESIS, SWTVK_RIGHT_PARENTHESIS, 433 VK_UNDERSCORE, SWTVK_UNDERSCORE 434 }; 435 436 public KeyEvent(Component source) { 437 super(source); 438 } 439 440 public KeyEvent(Component source, int id) { 441 super(source, id); 442 } 443 444 448 public char getKeyChar() { 449 return keyChar; 450 } 451 452 456 public void setKeyChar(char keyChar) { 457 this.keyChar = keyChar; 458 } 459 460 464 public int getKeyCode() { 465 return keyCode; 466 } 467 468 472 public void setKeyCode(int keyCode) { 473 this.keyCode = keyCode; 474 } 475 476 480 public void setModifiers(int modifiers) { 481 this.modifiers = modifiers; 482 } 483 484 485 public static int translateSWTKey(int swtKey) { 486 int awt = 0; 487 for (int i = 1; i < translationMap.length; i += 2) { 488 if (translationMap[i] == swtKey) { 489 awt = translationMap[i - 1]; 490 break; 491 } 492 } 493 return awt; 494 } 495 496 497 public static int translateAWTKey(int awtKey) { 498 int swt = 0; 499 for (int i = 0; i < translationMap.length; i += 2) { 500 if (translationMap[i] == awtKey) { 501 swt = translationMap[i + 1]; 502 break; 503 } 504 } 505 return swt; 506 } 507 508 } 509 | Popular Tags |