1. /*
  2. * @(#)KeyEvent.java 1.44 00/04/06
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt.event;
  11. import java.awt.Event;
  12. import java.awt.Component;
  13. import java.awt.Toolkit;
  14. /**
  15. * An event which indicates that a keystroke occurred in a component.
  16. * <P>
  17. * This low-level event is generated by a component object (such as a text
  18. * field) when a key is pressed, released, or typed.
  19. * The event is passed to every <code>KeyListener</code>
  20. * or <code>KeyAdapter</code> object which registered to receive such
  21. * events using the component's <code>addKeyListener</code> method.
  22. * (<code>KeyAdapter</code> objects implement the
  23. * <code>KeyListener</code> interface.) Each such listener object
  24. * gets this <code>KeyEvent</code> when the event occurs.
  25. *
  26. * <p>
  27. * <em>"Key typed" events</em> are higher-level and generally do not depend on
  28. * the platform or keyboard layout. They are generated when a character is
  29. * entered, and are the preferred way to find out about character input.
  30. * In the simplest case, a key typed event is produced by a single key press
  31. * (e.g., 'a'). Often, however, characters are produced by series of key
  32. * presses (e.g., 'shift' + 'a'), and the mapping from key pressed events to
  33. * key typed events may be many-to-one or many-to-many. Key releases are not
  34. * usually necessary to generate a key typed event, but there are some cases
  35. * where the key typed event is not generated until a key is released (e.g.,
  36. * entering ASCII sequences via the Alt-Numpad method in Windows).
  37. * No key typed events are generated for keys that don't generate characters
  38. * (e.g., action keys, modifier keys, etc.).
  39. * The getKeyChar method always returns a valid Unicode character or
  40. * CHAR_UNDEFINED.
  41. * For key pressed and key released events, the getKeyCode method returns
  42. * the event's keyCode. For key typed events, the getKeyCode method
  43. * always returns VK_UNDEFINED.
  44. *
  45. * <p>
  46. * <em>"Key pressed" and "key released" events</em> are lower-level and depend
  47. * on the platform and keyboard layout. They are generated whenever a key is
  48. * pressed or released, and are the only way to find out about keys that don't
  49. * generate character input (e.g., action keys, modifier keys, etc.). The key
  50. * being pressed or released is indicated by the getKeyCode method, which returns
  51. * a virtual key code.
  52. *
  53. * <p>
  54. * <em>Virtual key codes</em> are used to report which keyboard key has
  55. * been pressed, rather than a character generated by the combination
  56. * of one or more keystrokes (like "A", which comes from shift and "a").
  57. *
  58. * <P>
  59. * For example, pressing the Shift key will cause a KEY_PRESSED event
  60. * with a VK_SHIFT keyCode, while pressing the 'a' key will result in
  61. * a VK_A keyCode. After the 'a' key is released, a KEY_RELEASED event
  62. * will be fired with VK_A. Separately, a KEY_TYPED event with a keyChar
  63. * value of 'A' is generated.
  64. *
  65. * <P>
  66. * Notes:
  67. * <ul>
  68. * <li>Key combinations which do not result in characters, such as action keys
  69. * like F1 and the HELP key, do not generate KEY_TYPED events.
  70. * <li>Not all keyboards or systems are capable of generating all
  71. * virtual key codes. No attempt is made in Java to artificially
  72. * generate these keys.
  73. * <li>Virtual key codes do not identify a physical key, they depend on the
  74. * platform and keyboard layout. For
  75. * example, the key that on a Windows U.S. keyboard layout generates VK_Q,
  76. * generates VK_A on a Windows French keyboard layout.
  77. * <li>In order to support the platform-independent handling of action keys,
  78. * the Java platform uses a few additional virtual key constants for functions
  79. * that would otherwise have to be recognized by interpreting virtual key codes
  80. * and modifiers. For example, for Japanese Windows keyboards, VK_ALL_CANDIDATES
  81. * is returned instead of VK_CONVERT with the ALT modifer.
  82. * </ul>
  83. *
  84. * <P>
  85. * WARNING: Aside from those keys that are defined by the Java language
  86. * (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of the VK_
  87. * constants. Sun reserves the right to change these values as needed
  88. * to accomodate a wider range of keyboards in the future.
  89. *
  90. * @author Carl Quinn
  91. * @author Amy Fowler
  92. * @author Norbert Lindenberg
  93. * @version 1.44 04/06/00
  94. *
  95. * @see KeyAdapter
  96. * @see KeyListener
  97. * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/keylistener.html">Tutorial: Writing a Key Listener</a>
  98. * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
  99. *
  100. * @since 1.1
  101. */
  102. public class KeyEvent extends InputEvent {
  103. /**
  104. * The first number in the range of ids used for key events.
  105. */
  106. public static final int KEY_FIRST = 400;
  107. /**
  108. * The last number in the range of ids used for key events.
  109. */
  110. public static final int KEY_LAST = 402;
  111. /**
  112. * The "key typed" event. This event is generated when a character is
  113. * entered. In the simplest case, it is produced by a single key press.
  114. * Often, however, characters are produced by series of key presses, and
  115. * the mapping from key pressed events to key typed events may be
  116. * many-to-one or many-to-many.
  117. */
  118. public static final int KEY_TYPED = KEY_FIRST;
  119. /**
  120. * The "key pressed" event. This event is generated when a key
  121. * is pushed down.
  122. */
  123. public static final int KEY_PRESSED = 1 + KEY_FIRST; //Event.KEY_PRESS
  124. /**
  125. * The "key released" event. This event is generated when a key
  126. * is let up.
  127. */
  128. public static final int KEY_RELEASED = 2 + KEY_FIRST; //Event.KEY_RELEASE
  129. /* Virtual key codes. */
  130. public static final int VK_ENTER = '\n';
  131. public static final int VK_BACK_SPACE = '\b';
  132. public static final int VK_TAB = '\t';
  133. public static final int VK_CANCEL = 0x03;
  134. public static final int VK_CLEAR = 0x0C;
  135. public static final int VK_SHIFT = 0x10;
  136. public static final int VK_CONTROL = 0x11;
  137. public static final int VK_ALT = 0x12;
  138. public static final int VK_PAUSE = 0x13;
  139. public static final int VK_CAPS_LOCK = 0x14;
  140. public static final int VK_ESCAPE = 0x1B;
  141. public static final int VK_SPACE = 0x20;
  142. public static final int VK_PAGE_UP = 0x21;
  143. public static final int VK_PAGE_DOWN = 0x22;
  144. public static final int VK_END = 0x23;
  145. public static final int VK_HOME = 0x24;
  146. public static final int VK_LEFT = 0x25;
  147. public static final int VK_UP = 0x26;
  148. public static final int VK_RIGHT = 0x27;
  149. public static final int VK_DOWN = 0x28;
  150. public static final int VK_COMMA = 0x2C;
  151. /**
  152. * Constant for the "-" key.
  153. * @since 1.2
  154. */
  155. public static final int VK_MINUS = 0x2D;
  156. public static final int VK_PERIOD = 0x2E;
  157. public static final int VK_SLASH = 0x2F;
  158. /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
  159. public static final int VK_0 = 0x30;
  160. public static final int VK_1 = 0x31;
  161. public static final int VK_2 = 0x32;
  162. public static final int VK_3 = 0x33;
  163. public static final int VK_4 = 0x34;
  164. public static final int VK_5 = 0x35;
  165. public static final int VK_6 = 0x36;
  166. public static final int VK_7 = 0x37;
  167. public static final int VK_8 = 0x38;
  168. public static final int VK_9 = 0x39;
  169. public static final int VK_SEMICOLON = 0x3B;
  170. public static final int VK_EQUALS = 0x3D;
  171. /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
  172. public static final int VK_A = 0x41;
  173. public static final int VK_B = 0x42;
  174. public static final int VK_C = 0x43;
  175. public static final int VK_D = 0x44;
  176. public static final int VK_E = 0x45;
  177. public static final int VK_F = 0x46;
  178. public static final int VK_G = 0x47;
  179. public static final int VK_H = 0x48;
  180. public static final int VK_I = 0x49;
  181. public static final int VK_J = 0x4A;
  182. public static final int VK_K = 0x4B;
  183. public static final int VK_L = 0x4C;
  184. public static final int VK_M = 0x4D;
  185. public static final int VK_N = 0x4E;
  186. public static final int VK_O = 0x4F;
  187. public static final int VK_P = 0x50;
  188. public static final int VK_Q = 0x51;
  189. public static final int VK_R = 0x52;
  190. public static final int VK_S = 0x53;
  191. public static final int VK_T = 0x54;
  192. public static final int VK_U = 0x55;
  193. public static final int VK_V = 0x56;
  194. public static final int VK_W = 0x57;
  195. public static final int VK_X = 0x58;
  196. public static final int VK_Y = 0x59;
  197. public static final int VK_Z = 0x5A;
  198. public static final int VK_OPEN_BRACKET = 0x5B;
  199. public static final int VK_BACK_SLASH = 0x5C;
  200. public static final int VK_CLOSE_BRACKET = 0x5D;
  201. public static final int VK_NUMPAD0 = 0x60;
  202. public static final int VK_NUMPAD1 = 0x61;
  203. public static final int VK_NUMPAD2 = 0x62;
  204. public static final int VK_NUMPAD3 = 0x63;
  205. public static final int VK_NUMPAD4 = 0x64;
  206. public static final int VK_NUMPAD5 = 0x65;
  207. public static final int VK_NUMPAD6 = 0x66;
  208. public static final int VK_NUMPAD7 = 0x67;
  209. public static final int VK_NUMPAD8 = 0x68;
  210. public static final int VK_NUMPAD9 = 0x69;
  211. public static final int VK_MULTIPLY = 0x6A;
  212. public static final int VK_ADD = 0x6B;
  213. public static final int VK_SEPARATER = 0x6C;
  214. public static final int VK_SUBTRACT = 0x6D;
  215. public static final int VK_DECIMAL = 0x6E;
  216. public static final int VK_DIVIDE = 0x6F;
  217. public static final int VK_DELETE = 0x7F; /* ASCII DEL */
  218. public static final int VK_NUM_LOCK = 0x90;
  219. public static final int VK_SCROLL_LOCK = 0x91;
  220. /** Constant for the F1 function key. */
  221. public static final int VK_F1 = 0x70;
  222. /** Constant for the F2 function key. */
  223. public static final int VK_F2 = 0x71;
  224. /** Constant for the F3 function key. */
  225. public static final int VK_F3 = 0x72;
  226. /** Constant for the F4 function key. */
  227. public static final int VK_F4 = 0x73;
  228. /** Constant for the F5 function key. */
  229. public static final int VK_F5 = 0x74;
  230. /** Constant for the F6 function key. */
  231. public static final int VK_F6 = 0x75;
  232. /** Constant for the F7 function key. */
  233. public static final int VK_F7 = 0x76;
  234. /** Constant for the F8 function key. */
  235. public static final int VK_F8 = 0x77;
  236. /** Constant for the F9 function key. */
  237. public static final int VK_F9 = 0x78;
  238. /** Constant for the F10 function key. */
  239. public static final int VK_F10 = 0x79;
  240. /** Constant for the F11 function key. */
  241. public static final int VK_F11 = 0x7A;
  242. /** Constant for the F12 function key. */
  243. public static final int VK_F12 = 0x7B;
  244. /**
  245. * Constant for the F13 function key.
  246. * @since 1.2
  247. */
  248. /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */
  249. public static final int VK_F13 = 0xF000;
  250. /**
  251. * Constant for the F14 function key.
  252. * @since 1.2
  253. */
  254. public static final int VK_F14 = 0xF001;
  255. /**
  256. * Constant for the F15 function key.
  257. * @since 1.2
  258. */
  259. public static final int VK_F15 = 0xF002;
  260. /**
  261. * Constant for the F16 function key.
  262. * @since 1.2
  263. */
  264. public static final int VK_F16 = 0xF003;
  265. /**
  266. * Constant for the F17 function key.
  267. * @since 1.2
  268. */
  269. public static final int VK_F17 = 0xF004;
  270. /**
  271. * Constant for the F18 function key.
  272. * @since 1.2
  273. */
  274. public static final int VK_F18 = 0xF005;
  275. /**
  276. * Constant for the F19 function key.
  277. * @since 1.2
  278. */
  279. public static final int VK_F19 = 0xF006;
  280. /**
  281. * Constant for the F20 function key.
  282. * @since 1.2
  283. */
  284. public static final int VK_F20 = 0xF007;
  285. /**
  286. * Constant for the F21 function key.
  287. * @since 1.2
  288. */
  289. public static final int VK_F21 = 0xF008;
  290. /**
  291. * Constant for the F22 function key.
  292. * @since 1.2
  293. */
  294. public static final int VK_F22 = 0xF009;
  295. /**
  296. * Constant for the F23 function key.
  297. * @since 1.2
  298. */
  299. public static final int VK_F23 = 0xF00A;
  300. /**
  301. * Constant for the F24 function key.
  302. * @since 1.2
  303. */
  304. public static final int VK_F24 = 0xF00B;
  305. public static final int VK_PRINTSCREEN = 0x9A;
  306. public static final int VK_INSERT = 0x9B;
  307. public static final int VK_HELP = 0x9C;
  308. public static final int VK_META = 0x9D;
  309. public static final int VK_BACK_QUOTE = 0xC0;
  310. public static final int VK_QUOTE = 0xDE;
  311. /**
  312. * Constant for the key pad arrow up function key.
  313. * @since 1.2
  314. */
  315. public static final int VK_KP_UP = 0xE0;
  316. /**
  317. * Constant for the key pad arrow down function key.
  318. * @since 1.2
  319. */
  320. public static final int VK_KP_DOWN = 0xE1;
  321. /**
  322. * Constant for the key pad arrow left function key.
  323. * @since 1.2
  324. */
  325. public static final int VK_KP_LEFT = 0xE2;
  326. /**
  327. * Constant for the key pad arrow right function key.
  328. * @since 1.2
  329. */
  330. public static final int VK_KP_RIGHT = 0xE3;
  331. /* For European keyboards */
  332. /** @since 1.2 */
  333. public static final int VK_DEAD_GRAVE = 0x80;
  334. /** @since 1.2 */
  335. public static final int VK_DEAD_ACUTE = 0x81;
  336. /** @since 1.2 */
  337. public static final int VK_DEAD_CIRCUMFLEX = 0x82;
  338. /** @since 1.2 */
  339. public static final int VK_DEAD_TILDE = 0x83;
  340. /** @since 1.2 */
  341. public static final int VK_DEAD_MACRON = 0x84;
  342. /** @since 1.2 */
  343. public static final int VK_DEAD_BREVE = 0x85;
  344. /** @since 1.2 */
  345. public static final int VK_DEAD_ABOVEDOT = 0x86;
  346. /** @since 1.2 */
  347. public static final int VK_DEAD_DIAERESIS = 0x87;
  348. /** @since 1.2 */
  349. public static final int VK_DEAD_ABOVERING = 0x88;
  350. /** @since 1.2 */
  351. public static final int VK_DEAD_DOUBLEACUTE = 0x89;
  352. /** @since 1.2 */
  353. public static final int VK_DEAD_CARON = 0x8a;
  354. /** @since 1.2 */
  355. public static final int VK_DEAD_CEDILLA = 0x8b;
  356. /** @since 1.2 */
  357. public static final int VK_DEAD_OGONEK = 0x8c;
  358. /** @since 1.2 */
  359. public static final int VK_DEAD_IOTA = 0x8d;
  360. /** @since 1.2 */
  361. public static final int VK_DEAD_VOICED_SOUND = 0x8e;
  362. /** @since 1.2 */
  363. public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f;
  364. /** @since 1.2 */
  365. public static final int VK_AMPERSAND = 0x96;
  366. /** @since 1.2 */
  367. public static final int VK_ASTERISK = 0x97;
  368. /** @since 1.2 */
  369. public static final int VK_QUOTEDBL = 0x98;
  370. /** @since 1.2 */
  371. public static final int VK_LESS = 0x99;
  372. /** @since 1.2 */
  373. public static final int VK_GREATER = 0xa0;
  374. /** @since 1.2 */
  375. public static final int VK_BRACELEFT = 0xa1;
  376. /** @since 1.2 */
  377. public static final int VK_BRACERIGHT = 0xa2;
  378. /**
  379. * Constant for the "@" key.
  380. * @since 1.2
  381. */
  382. public static final int VK_AT = 0x0200;
  383. /**
  384. * Constant for the ":" key.
  385. * @since 1.2
  386. */
  387. public static final int VK_COLON = 0x0201;
  388. /**
  389. * Constant for the "^" key.
  390. * @since 1.2
  391. */
  392. public static final int VK_CIRCUMFLEX = 0x0202;
  393. /**
  394. * Constant for the "$" key.
  395. * @since 1.2
  396. */
  397. public static final int VK_DOLLAR = 0x0203;
  398. /**
  399. * Constant for the Euro currency sign key.
  400. * @since 1.2
  401. */
  402. public static final int VK_EURO_SIGN = 0x0204;
  403. /**
  404. * Constant for the "!" key.
  405. * @since 1.2
  406. */
  407. public static final int VK_EXCLAMATION_MARK = 0x0205;
  408. /**
  409. * Constant for the inverted exclamation mark key.
  410. * @since 1.2
  411. */
  412. public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206;
  413. /**
  414. * Constant for the "(" key.
  415. * @since 1.2
  416. */
  417. public static final int VK_LEFT_PARENTHESIS = 0x0207;
  418. /**
  419. * Constant for the "#" key.
  420. * @since 1.2
  421. */
  422. public static final int VK_NUMBER_SIGN = 0x0208;
  423. /**
  424. * Constant for the "+" key.
  425. * @since 1.2
  426. */
  427. public static final int VK_PLUS = 0x0209;
  428. /**
  429. * Constant for the ")" key.
  430. * @since 1.2
  431. */
  432. public static final int VK_RIGHT_PARENTHESIS = 0x020A;
  433. /**
  434. * Constant for the "_" key.
  435. * @since 1.2
  436. */
  437. public static final int VK_UNDERSCORE = 0x020B;
  438. /* for input method support on Asian Keyboards */
  439. /* not clear what this means - listed in Win32 API */
  440. public static final int VK_FINAL = 0x0018;
  441. /** Constant for the Convert function key. */
  442. /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */
  443. public static final int VK_CONVERT = 0x001C;
  444. /** Constant for the Don't Convert function key. */
  445. /* Japanese PC 106 keyboard: muhenkan */
  446. public static final int VK_NONCONVERT = 0x001D;
  447. /** Constant for the Accept or Commit function key. */
  448. /* Japanese Solaris keyboard: kakutei */
  449. public static final int VK_ACCEPT = 0x001E;
  450. /* not clear what this means - listed in Win32 API */
  451. public static final int VK_MODECHANGE = 0x001F;
  452. /* replaced by VK_KANA_LOCK for Win32 and Solaris; might still be used on other platforms */
  453. public static final int VK_KANA = 0x0015;
  454. /* replaced by VK_INPUT_METHOD_ON_OFF for Win32 and Solaris; might still be used for other platforms */
  455. public static final int VK_KANJI = 0x0019;
  456. /**
  457. * Constant for the Alphanumeric function key.
  458. * @since 1.2
  459. */
  460. /* Japanese PC 106 keyboard: eisuu */
  461. public static final int VK_ALPHANUMERIC = 0x00F0;
  462. /**
  463. * Constant for the Katakana function key.
  464. * @since 1.2
  465. */
  466. /* Japanese PC 106 keyboard: katakana */
  467. public static final int VK_KATAKANA = 0x00F1;
  468. /**
  469. * Constant for the Hiragana function key.
  470. * @since 1.2
  471. */
  472. /* Japanese PC 106 keyboard: hiragana */
  473. public static final int VK_HIRAGANA = 0x00F2;
  474. /**
  475. * Constant for the Full-Width Characters function key.
  476. * @since 1.2
  477. */
  478. /* Japanese PC 106 keyboard: zenkaku */
  479. public static final int VK_FULL_WIDTH = 0x00F3;
  480. /**
  481. * Constant for the Half-Width Characters function key.
  482. * @since 1.2
  483. */
  484. /* Japanese PC 106 keyboard: hankaku */
  485. public static final int VK_HALF_WIDTH = 0x00F4;
  486. /**
  487. * Constant for the Roman Characters function key.
  488. * @since 1.2
  489. */
  490. /* Japanese PC 106 keyboard: roumaji */
  491. public static final int VK_ROMAN_CHARACTERS = 0x00F5;
  492. /**
  493. * Constant for the All Candidates function key.
  494. * @since 1.2
  495. */
  496. /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */
  497. public static final int VK_ALL_CANDIDATES = 0x0100;
  498. /**
  499. * Constant for the Previous Candidate function key.
  500. * @since 1.2
  501. */
  502. /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */
  503. public static final int VK_PREVIOUS_CANDIDATE = 0x0101;
  504. /**
  505. * Constant for the Code Input function key.
  506. * @since 1.2
  507. */
  508. /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */
  509. public static final int VK_CODE_INPUT = 0x0102;
  510. /**
  511. * Constant for the Japanese-Katakana function key.
  512. * This key switches to a Japanese input method and selects its Katakana input mode.
  513. * @since 1.2
  514. */
  515. /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */
  516. public static final int VK_JAPANESE_KATAKANA = 0x0103;
  517. /**
  518. * Constant for the Japanese-Hiragana function key.
  519. * This key switches to a Japanese input method and selects its Hiragana input mode.
  520. * @since 1.2
  521. */
  522. /* Japanese Macintosh keyboard */
  523. public static final int VK_JAPANESE_HIRAGANA = 0x0104;
  524. /**
  525. * Constant for the Japanese-Roman function key.
  526. * This key switches to a Japanese input method and selects its Roman-Direct input mode.
  527. * @since 1.2
  528. */
  529. /* Japanese Macintosh keyboard */
  530. public static final int VK_JAPANESE_ROMAN = 0x0105;
  531. /**
  532. * Constant for the locking Kana function key.
  533. * This key locks the keyboard into a Kana layout.
  534. * @since 1.3
  535. */
  536. /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */
  537. public static final int VK_KANA_LOCK = 0x0106;
  538. /**
  539. * Constant for the input method on/off key.
  540. * @since 1.3
  541. */
  542. /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */
  543. public static final int VK_INPUT_METHOD_ON_OFF = 0x0107;
  544. /* for Sun keyboards */
  545. /** @since 1.2 */
  546. public static final int VK_CUT = 0xFFD1;
  547. /** @since 1.2 */
  548. public static final int VK_COPY = 0xFFCD;
  549. /** @since 1.2 */
  550. public static final int VK_PASTE = 0xFFCF;
  551. /** @since 1.2 */
  552. public static final int VK_UNDO = 0xFFCB;
  553. /** @since 1.2 */
  554. public static final int VK_AGAIN = 0xFFC9;
  555. /** @since 1.2 */
  556. public static final int VK_FIND = 0xFFD0;
  557. /** @since 1.2 */
  558. public static final int VK_PROPS = 0xFFCA;
  559. /** @since 1.2 */
  560. public static final int VK_STOP = 0xFFC8;
  561. /**
  562. * Constant for the Compose function key.
  563. * @since 1.2
  564. */
  565. public static final int VK_COMPOSE = 0xFF20;
  566. /**
  567. * Constant for the AltGraph function key.
  568. * @since 1.2
  569. */
  570. public static final int VK_ALT_GRAPH = 0xFF7E;
  571. /**
  572. * KEY_TYPED events do not have a keyCode value.
  573. * This value is used, instead.
  574. */
  575. public static final int VK_UNDEFINED = 0x0;
  576. /**
  577. * KEY_PRESSED and KEY_RELEASED events which do not map to a
  578. * valid Unicode character use this for the keyChar value.
  579. */
  580. public static final char CHAR_UNDEFINED = 0x0ffff;
  581. /**
  582. * The unique value assigned to each of the keys on the
  583. * keyboard. There is a common set of key codes that
  584. * can be fired by most keyboards.
  585. * The symbolic name for a key code should be used rather
  586. * than the code value itself.
  587. *
  588. * @serial
  589. * @see getKeyCode()
  590. * @see setKeyCode()
  591. */
  592. int keyCode;
  593. /**
  594. * <code>keyChar</code> is a valid unicode character
  595. * that is fired by a key or a key combination on
  596. * a keyboard.
  597. *
  598. * @serial
  599. * @see getKeyChar()
  600. * @see setKeyChar()
  601. */
  602. char keyChar;
  603. /*
  604. * JDK 1.1 serialVersionUID
  605. */
  606. private static final long serialVersionUID = -2352130953028126954L;
  607. static {
  608. /* ensure that the necessary native libraries are loaded */
  609. NativeLibLoader.loadLibraries();
  610. initIDs();
  611. }
  612. /**
  613. * Initialize JNI field and method IDs for fields that may be
  614. accessed from C.
  615. */
  616. private static native void initIDs();
  617. /**
  618. * Constructs a KeyEvent object.
  619. *
  620. * @param source the Component that originated the event
  621. * @param id an integer identifying the type of event
  622. * @param when a long integer that specifys the time the event occurred
  623. * @param modifiers the modifier keys down during event
  624. * (shift, ctrl, alt, meta)
  625. * @param keyCode the integer code for an actual key, or VK_UNDEFINED
  626. * (for a key-typed event)
  627. * @param keyChar the Unicode character generated by this event, or
  628. * CHAR_UNDEFINED (for key-pressed and key-released
  629. * events which do not map to a valid Unicode character)
  630. */
  631. public KeyEvent(Component source, int id, long when, int modifiers,
  632. int keyCode, char keyChar) {
  633. super(source, id, when, modifiers);
  634. if (id == KEY_TYPED && keyChar == CHAR_UNDEFINED) {
  635. throw new IllegalArgumentException("invalid keyChar");
  636. }
  637. if (id == KEY_TYPED && keyCode != VK_UNDEFINED) {
  638. throw new IllegalArgumentException("invalid keyCode");
  639. }
  640. this.keyCode = keyCode;
  641. this.keyChar = keyChar;
  642. }
  643. /*
  644. * @deprecated, as of JDK1.1 - Do NOT USE; will be removed in 1.1.1.
  645. */
  646. public KeyEvent(Component source, int id, long when, int modifiers,
  647. int keyCode) {
  648. this(source, id, when, modifiers, keyCode, (char)keyCode);
  649. }
  650. /**
  651. * Set the source of this KeyEvent. Dispatching this event subsequent
  652. * to this operation will send this event to the new Object.
  653. *
  654. * @param newSource the KeyEvent's new source.
  655. */
  656. public void setSource(Object newSource) {
  657. source = newSource;
  658. }
  659. /**
  660. * Returns the integer key-code associated with the key in this event.
  661. *
  662. * @return the integer code for an actual key on the keyboard.
  663. * (For KEY_TYPED events, keyCode is VK_UNDEFINED.)
  664. */
  665. public int getKeyCode() {
  666. return keyCode;
  667. }
  668. /**
  669. * Set the keyCode value to indicate a physical key.
  670. *
  671. * @param keyCode an integer corresponding to an actual key on the keyboard.
  672. */
  673. public void setKeyCode(int keyCode) {
  674. this.keyCode = keyCode;
  675. }
  676. /**
  677. * Set the keyChar value to indicate a logical character.
  678. *
  679. * @param keyChar a char corresponding to to the combination of keystrokes
  680. * that make up this event.
  681. */
  682. public void setKeyChar(char keyChar) {
  683. this.keyChar = keyChar;
  684. }
  685. /**
  686. * Set the modifiers to indicate additional keys that were held down
  687. * (shift, ctrl, alt, meta) defined as part of InputEvent.
  688. * <p>
  689. * NOTE: use of this method is not recommended, because many AWT
  690. * implementations do not recognize modifier changes. This is
  691. * especially true for KEY_TYPED events where the shift modifier
  692. * is changed.
  693. *
  694. * @param modifiers an integer combination of the modifier constants.
  695. *
  696. * @see InputEvent
  697. *
  698. * @deprecated, as of JDK1.1.4
  699. */
  700. public void setModifiers(int modifiers) {
  701. this.modifiers = modifiers;
  702. }
  703. /**
  704. * Returns the character associated with the key in this event.
  705. * For example, the key-typed event for shift + "a" returns the
  706. * value for "A".
  707. *
  708. * @return the Unicode character defined for this key event.
  709. * If no valid Unicode character exists for this key event,
  710. * keyChar is CHAR_UNDEFINED.
  711. */
  712. public char getKeyChar() {
  713. return keyChar;
  714. }
  715. /**
  716. * Returns a String describing the keyCode, such as "HOME", "F1" or "A".
  717. * These strings can be localized by changing the awt.properties file.
  718. *
  719. * @return string a text description for a physical key, identified by
  720. * its keyCode
  721. */
  722. public static String getKeyText(int keyCode) {
  723. if (keyCode >= VK_0 && keyCode <= VK_9 ||
  724. keyCode >= VK_A && keyCode <= VK_Z) {
  725. return String.valueOf((char)keyCode);
  726. }
  727. // Check for other ASCII keyCodes.
  728. int index = ",./;=[\\]".indexOf(keyCode);
  729. if (index >= 0) {
  730. return String.valueOf((char)keyCode);
  731. }
  732. switch(keyCode) {
  733. case VK_ENTER: return Toolkit.getProperty("AWT.enter", "Enter");
  734. case VK_BACK_SPACE: return Toolkit.getProperty("AWT.backSpace", "Backspace");
  735. case VK_TAB: return Toolkit.getProperty("AWT.tab", "Tab");
  736. case VK_CANCEL: return Toolkit.getProperty("AWT.cancel", "Cancel");
  737. case VK_CLEAR: return Toolkit.getProperty("AWT.clear", "Clear");
  738. case VK_SHIFT: return Toolkit.getProperty("AWT.shift", "Shift");
  739. case VK_CONTROL: return Toolkit.getProperty("AWT.control", "Control");
  740. case VK_ALT: return Toolkit.getProperty("AWT.alt", "Alt");
  741. case VK_PAUSE: return Toolkit.getProperty("AWT.pause", "Pause");
  742. case VK_CAPS_LOCK: return Toolkit.getProperty("AWT.capsLock", "Caps Lock");
  743. case VK_ESCAPE: return Toolkit.getProperty("AWT.escape", "Escape");
  744. case VK_SPACE: return Toolkit.getProperty("AWT.space", "Space");
  745. case VK_PAGE_UP: return Toolkit.getProperty("AWT.pgup", "Page Up");
  746. case VK_PAGE_DOWN: return Toolkit.getProperty("AWT.pgdn", "Page Down");
  747. case VK_END: return Toolkit.getProperty("AWT.end", "End");
  748. case VK_HOME: return Toolkit.getProperty("AWT.home", "Home");
  749. case VK_LEFT: return Toolkit.getProperty("AWT.left", "Left");
  750. case VK_UP: return Toolkit.getProperty("AWT.up", "Up");
  751. case VK_RIGHT: return Toolkit.getProperty("AWT.right", "Right");
  752. case VK_DOWN: return Toolkit.getProperty("AWT.down", "Down");
  753. // handled by ASCII value above:
  754. // comma, period, slash, 0-9, semicolon, equals, A-Z,
  755. // open_bracket, back_slash, close_bracket
  756. // numpad numeric keys handled below
  757. case VK_MULTIPLY: return Toolkit.getProperty("AWT.multiply", "NumPad *");
  758. case VK_ADD: return Toolkit.getProperty("AWT.add", "NumPad +");
  759. case VK_SEPARATER: return Toolkit.getProperty("AWT.separater", "NumPad ,");
  760. case VK_SUBTRACT: return Toolkit.getProperty("AWT.subtract", "NumPad -");
  761. case VK_DECIMAL: return Toolkit.getProperty("AWT.decimal", "NumPad .");
  762. case VK_DIVIDE: return Toolkit.getProperty("AWT.divide", "NumPad /");
  763. case VK_DELETE: return Toolkit.getProperty("AWT.delete", "Delete");
  764. case VK_NUM_LOCK: return Toolkit.getProperty("AWT.numLock", "Num Lock");
  765. case VK_SCROLL_LOCK: return Toolkit.getProperty("AWT.scrollLock", "Scroll Lock");
  766. case VK_F1: return Toolkit.getProperty("AWT.f1", "F1");
  767. case VK_F2: return Toolkit.getProperty("AWT.f2", "F2");
  768. case VK_F3: return Toolkit.getProperty("AWT.f3", "F3");
  769. case VK_F4: return Toolkit.getProperty("AWT.f4", "F4");
  770. case VK_F5: return Toolkit.getProperty("AWT.f5", "F5");
  771. case VK_F6: return Toolkit.getProperty("AWT.f6", "F6");
  772. case VK_F7: return Toolkit.getProperty("AWT.f7", "F7");
  773. case VK_F8: return Toolkit.getProperty("AWT.f8", "F8");
  774. case VK_F9: return Toolkit.getProperty("AWT.f9", "F9");
  775. case VK_F10: return Toolkit.getProperty("AWT.f10", "F10");
  776. case VK_F11: return Toolkit.getProperty("AWT.f11", "F11");
  777. case VK_F12: return Toolkit.getProperty("AWT.f12", "F12");
  778. case VK_F13: return Toolkit.getProperty("AWT.f13", "F13");
  779. case VK_F14: return Toolkit.getProperty("AWT.f14", "F14");
  780. case VK_F15: return Toolkit.getProperty("AWT.f15", "F15");
  781. case VK_F16: return Toolkit.getProperty("AWT.f16", "F16");
  782. case VK_F17: return Toolkit.getProperty("AWT.f17", "F17");
  783. case VK_F18: return Toolkit.getProperty("AWT.f18", "F18");
  784. case VK_F19: return Toolkit.getProperty("AWT.f19", "F19");
  785. case VK_F20: return Toolkit.getProperty("AWT.f20", "F20");
  786. case VK_F21: return Toolkit.getProperty("AWT.f21", "F21");
  787. case VK_F22: return Toolkit.getProperty("AWT.f22", "F22");
  788. case VK_F23: return Toolkit.getProperty("AWT.f23", "F23");
  789. case VK_F24: return Toolkit.getProperty("AWT.f24", "F24");
  790. case VK_PRINTSCREEN: return Toolkit.getProperty("AWT.printScreen", "Print Screen");
  791. case VK_INSERT: return Toolkit.getProperty("AWT.insert", "Insert");
  792. case VK_HELP: return Toolkit.getProperty("AWT.help", "Help");
  793. case VK_META: return Toolkit.getProperty("AWT.meta", "Meta");
  794. case VK_BACK_QUOTE: return Toolkit.getProperty("AWT.backQuote", "Back Quote");
  795. case VK_QUOTE: return Toolkit.getProperty("AWT.quote", "Quote");
  796. case VK_KP_UP: return Toolkit.getProperty("AWT.up", "Up");
  797. case VK_KP_DOWN: return Toolkit.getProperty("AWT.down", "Down");
  798. case VK_KP_LEFT: return Toolkit.getProperty("AWT.left", "Left");
  799. case VK_KP_RIGHT: return Toolkit.getProperty("AWT.right", "Right");
  800. case VK_DEAD_GRAVE: return Toolkit.getProperty("AWT.deadGrave", "Dead Grave");
  801. case VK_DEAD_ACUTE: return Toolkit.getProperty("AWT.deadAcute", "Dead Acute");
  802. case VK_DEAD_CIRCUMFLEX: return Toolkit.getProperty("AWT.deadCircumflex", "Dead Circumflex");
  803. case VK_DEAD_TILDE: return Toolkit.getProperty("AWT.deadTilde", "Dead Tilde");
  804. case VK_DEAD_MACRON: return Toolkit.getProperty("AWT.deadMacron", "Dead Macron");
  805. case VK_DEAD_BREVE: return Toolkit.getProperty("AWT.deadBreve", "Dead Breve");
  806. case VK_DEAD_ABOVEDOT: return Toolkit.getProperty("AWT.deadAboveDot", "Dead Above Dot");
  807. case VK_DEAD_DIAERESIS: return Toolkit.getProperty("AWT.deadDiaeresis", "Dead Diaeresis");
  808. case VK_DEAD_ABOVERING: return Toolkit.getProperty("AWT.deadAboveRing", "Dead Above Ring");
  809. case VK_DEAD_DOUBLEACUTE: return Toolkit.getProperty("AWT.deadDoubleAcute", "Dead Double Acute");
  810. case VK_DEAD_CARON: return Toolkit.getProperty("AWT.deadCaron", "Dead Caron");
  811. case VK_DEAD_CEDILLA: return Toolkit.getProperty("AWT.deadCedilla", "Dead Cedilla");
  812. case VK_DEAD_OGONEK: return Toolkit.getProperty("AWT.deadOgonek", "Dead Ogonek");
  813. case VK_DEAD_IOTA: return Toolkit.getProperty("AWT.deadIota", "Dead Iota");
  814. case VK_DEAD_VOICED_SOUND: return Toolkit.getProperty("AWT.deadVoicedSound", "Dead Voiced Sound");
  815. case VK_DEAD_SEMIVOICED_SOUND: return Toolkit.getProperty("AWT.deadSemivoicedSound", "Dead Semivoiced Sound");
  816. case VK_AMPERSAND: return Toolkit.getProperty("AWT.ampersand", "Ampersand");
  817. case VK_ASTERISK: return Toolkit.getProperty("AWT.asterisk", "Asterisk");
  818. case VK_QUOTEDBL: return Toolkit.getProperty("AWT.quoteDbl", "Double Quote");
  819. case VK_LESS: return Toolkit.getProperty("AWT.Less", "Less");
  820. case VK_GREATER: return Toolkit.getProperty("AWT.greater", "Greater");
  821. case VK_BRACELEFT: return Toolkit.getProperty("AWT.braceLeft", "Left Brace");
  822. case VK_BRACERIGHT: return Toolkit.getProperty("AWT.braceRight", "Right Brace");
  823. case VK_AT: return Toolkit.getProperty("AWT.at", "At");
  824. case VK_COLON: return Toolkit.getProperty("AWT.colon", "Colon");
  825. case VK_CIRCUMFLEX: return Toolkit.getProperty("AWT.circumflex", "Circumflex");
  826. case VK_DOLLAR: return Toolkit.getProperty("AWT.dollar", "Dollar");
  827. case VK_EURO_SIGN: return Toolkit.getProperty("AWT.euro", "Euro");
  828. case VK_EXCLAMATION_MARK: return Toolkit.getProperty("AWT.exclamationMark", "Exclamation Mark");
  829. case VK_INVERTED_EXCLAMATION_MARK: return Toolkit.getProperty("AWT.invertedExclamationMark", "Inverted Exclamation Mark");
  830. case VK_LEFT_PARENTHESIS: return Toolkit.getProperty("AWT.leftParenthesis", "Left Parenthesis");
  831. case VK_NUMBER_SIGN: return Toolkit.getProperty("AWT.numberSign", "Number Sign");
  832. case VK_MINUS: return Toolkit.getProperty("AWT.minus", "Minus");
  833. case VK_PLUS: return Toolkit.getProperty("AWT.plus", "Plus");
  834. case VK_RIGHT_PARENTHESIS: return Toolkit.getProperty("AWT.rightParenthesis", "Right Parenthesis");
  835. case VK_UNDERSCORE: return Toolkit.getProperty("AWT.underscore", "Underscore");
  836. case VK_FINAL: return Toolkit.getProperty("AWT.final", "Final");
  837. case VK_CONVERT: return Toolkit.getProperty("AWT.convert", "Convert");
  838. case VK_NONCONVERT: return Toolkit.getProperty("AWT.noconvert", "No Convert");
  839. case VK_ACCEPT: return Toolkit.getProperty("AWT.accept", "Accept");
  840. case VK_MODECHANGE: return Toolkit.getProperty("AWT.modechange", "Mode Change");
  841. case VK_KANA: return Toolkit.getProperty("AWT.kana", "Kana");
  842. case VK_KANJI: return Toolkit.getProperty("AWT.kanji", "Kanji");
  843. case VK_ALPHANUMERIC: return Toolkit.getProperty("AWT.alphanumeric", "Alphanumeric");
  844. case VK_KATAKANA: return Toolkit.getProperty("AWT.katakana", "Katakana");
  845. case VK_HIRAGANA: return Toolkit.getProperty("AWT.hiragana", "Hiragana");
  846. case VK_FULL_WIDTH: return Toolkit.getProperty("AWT.fullWidth", "Full-Width");
  847. case VK_HALF_WIDTH: return Toolkit.getProperty("AWT.halfWidth", "Half-Width");
  848. case VK_ROMAN_CHARACTERS: return Toolkit.getProperty("AWT.romanCharacters", "Roman Characters");
  849. case VK_ALL_CANDIDATES: return Toolkit.getProperty("AWT.allCandidates", "All Candidates");
  850. case VK_PREVIOUS_CANDIDATE: return Toolkit.getProperty("AWT.previousCandidate", "Previous Candidate");
  851. case VK_CODE_INPUT: return Toolkit.getProperty("AWT.codeInput", "Code Input");
  852. case VK_JAPANESE_KATAKANA: return Toolkit.getProperty("AWT.japaneseKatakana", "Japanese Katakana");
  853. case VK_JAPANESE_HIRAGANA: return Toolkit.getProperty("AWT.japaneseHiragana", "Japanese Hiragana");
  854. case VK_JAPANESE_ROMAN: return Toolkit.getProperty("AWT.japaneseRoman", "Japanese Roman");
  855. case VK_KANA_LOCK: return Toolkit.getProperty("AWT.kanaLock", "Kana Lock");
  856. case VK_INPUT_METHOD_ON_OFF: return Toolkit.getProperty("AWT.inputMethodOnOff", "Input Method On/Off");
  857. case VK_AGAIN: return Toolkit.getProperty("AWT.again", "Again");
  858. case VK_UNDO: return Toolkit.getProperty("AWT.undo", "Undo");
  859. case VK_COPY: return Toolkit.getProperty("AWT.copy", "Copy");
  860. case VK_PASTE: return Toolkit.getProperty("AWT.paste", "Paste");
  861. case VK_CUT: return Toolkit.getProperty("AWT.cut", "Cut");
  862. case VK_FIND: return Toolkit.getProperty("AWT.find", "Find");
  863. case VK_PROPS: return Toolkit.getProperty("AWT.props", "Props");
  864. case VK_STOP: return Toolkit.getProperty("AWT.stop", "Stop");
  865. case VK_COMPOSE: return Toolkit.getProperty("AWT.compose", "Compose");
  866. case VK_ALT_GRAPH: return Toolkit.getProperty("AWT.altGraph", "Alt Graph");
  867. }
  868. if (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9) {
  869. String numpad = Toolkit.getProperty("AWT.numpad", "NumPad");
  870. char c = (char)(keyCode - VK_NUMPAD0 + '0');
  871. return numpad + "-" + c;
  872. }
  873. String unknown = Toolkit.getProperty("AWT.unknown", "Unknown keyCode");
  874. return unknown + ": 0x" + Integer.toString(keyCode, 16);
  875. }
  876. /**
  877. * Returns a String describing the modifier key(s), such as "Shift",
  878. * or "Ctrl+Shift". These strings can be localized by changing the
  879. * awt.properties file.
  880. *
  881. * @return string a text description of the combination of modifier
  882. * keys that were held down during the event
  883. */
  884. public static String getKeyModifiersText(int modifiers) {
  885. StringBuffer buf = new StringBuffer();
  886. if ((modifiers & InputEvent.META_MASK) != 0) {
  887. buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
  888. buf.append("+");
  889. }
  890. if ((modifiers & InputEvent.CTRL_MASK) != 0) {
  891. buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
  892. buf.append("+");
  893. }
  894. if ((modifiers & InputEvent.ALT_MASK) != 0) {
  895. buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
  896. buf.append("+");
  897. }
  898. if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
  899. buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
  900. buf.append("+");
  901. }
  902. if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
  903. buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
  904. buf.append("+");
  905. }
  906. if (buf.length() > 0) {
  907. buf.setLength(buf.length()-1); // remove trailing '+'
  908. }
  909. return buf.toString();
  910. }
  911. /** Returns whether or not the key in this event is an "action" key,
  912. * as defined in Event.java.
  913. *
  914. * @return boolean value, true if the key is an "action" key
  915. *
  916. * @see Event
  917. */
  918. public boolean isActionKey() {
  919. switch (keyCode) {
  920. case VK_HOME:
  921. case VK_END:
  922. case VK_PAGE_UP:
  923. case VK_PAGE_DOWN:
  924. case VK_UP:
  925. case VK_DOWN:
  926. case VK_LEFT:
  927. case VK_RIGHT:
  928. case VK_KP_LEFT:
  929. case VK_KP_UP:
  930. case VK_KP_RIGHT:
  931. case VK_KP_DOWN:
  932. case VK_F1:
  933. case VK_F2:
  934. case VK_F3:
  935. case VK_F4:
  936. case VK_F5:
  937. case VK_F6:
  938. case VK_F7:
  939. case VK_F8:
  940. case VK_F9:
  941. case VK_F10:
  942. case VK_F11:
  943. case VK_F12:
  944. case VK_F13:
  945. case VK_F14:
  946. case VK_F15:
  947. case VK_F16:
  948. case VK_F17:
  949. case VK_F18:
  950. case VK_F19:
  951. case VK_F20:
  952. case VK_F21:
  953. case VK_F22:
  954. case VK_F23:
  955. case VK_F24:
  956. case VK_PRINTSCREEN:
  957. case VK_SCROLL_LOCK:
  958. case VK_CAPS_LOCK:
  959. case VK_NUM_LOCK:
  960. case VK_PAUSE:
  961. case VK_INSERT:
  962. case VK_FINAL:
  963. case VK_CONVERT:
  964. case VK_NONCONVERT:
  965. case VK_ACCEPT:
  966. case VK_MODECHANGE:
  967. case VK_KANA:
  968. case VK_KANJI:
  969. case VK_ALPHANUMERIC:
  970. case VK_KATAKANA:
  971. case VK_HIRAGANA:
  972. case VK_FULL_WIDTH:
  973. case VK_HALF_WIDTH:
  974. case VK_ROMAN_CHARACTERS:
  975. case VK_ALL_CANDIDATES:
  976. case VK_PREVIOUS_CANDIDATE:
  977. case VK_CODE_INPUT:
  978. case VK_JAPANESE_KATAKANA:
  979. case VK_JAPANESE_HIRAGANA:
  980. case VK_JAPANESE_ROMAN:
  981. case VK_KANA_LOCK:
  982. case VK_INPUT_METHOD_ON_OFF:
  983. case VK_AGAIN:
  984. case VK_UNDO:
  985. case VK_COPY:
  986. case VK_PASTE:
  987. case VK_CUT:
  988. case VK_FIND:
  989. case VK_PROPS:
  990. case VK_STOP:
  991. case VK_HELP:
  992. return true;
  993. }
  994. return false;
  995. }
  996. /**
  997. * Returns a parameter string identifying this event.
  998. * This method is useful for event-logging and for debugging.
  999. *
  1000. * @return a string identifying the event and its attributes
  1001. */
  1002. public String paramString() {
  1003. String typeStr;
  1004. switch(id) {
  1005. case KEY_PRESSED:
  1006. typeStr = "KEY_PRESSED";
  1007. break;
  1008. case KEY_RELEASED:
  1009. typeStr = "KEY_RELEASED";
  1010. break;
  1011. case KEY_TYPED:
  1012. typeStr = "KEY_TYPED";
  1013. break;
  1014. default:
  1015. typeStr = "unknown type";
  1016. }
  1017. String str = typeStr + ",keyCode=" + keyCode;
  1018. if (isActionKey() || keyCode == VK_ENTER || keyCode == VK_BACK_SPACE ||
  1019. keyCode == VK_TAB || keyCode == VK_ESCAPE || keyCode == VK_DELETE ||
  1020. (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9) ||
  1021. keyCode == VK_COMPOSE || keyCode == VK_ALT_GRAPH) {
  1022. str += "," + getKeyText(keyCode);
  1023. } else if (keyChar == '\n' || keyChar == '\b' ||
  1024. keyChar == '\t' || keyChar == VK_ESCAPE || keyChar == VK_DELETE) {
  1025. str += "," + getKeyText(keyChar);
  1026. } else {
  1027. str += ",keyChar='" + keyChar + "'";
  1028. }
  1029. if (modifiers > 0) {
  1030. str += ",modifiers=" + getKeyModifiersText(modifiers);
  1031. }
  1032. return str;
  1033. }
  1034. }