AwtKeyInput.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. * Copyright (c) 2009-2010 jMonkeyEngine
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. package com.jme3.input.awt;
  33. import com.jme3.input.KeyInput;
  34. import com.jme3.input.RawInputListener;
  35. import com.jme3.input.event.KeyInputEvent;
  36. import java.awt.Component;
  37. import java.awt.event.KeyEvent;
  38. import java.awt.event.KeyListener;
  39. import java.util.ArrayList;
  40. import java.util.BitSet;
  41. import java.util.logging.Level;
  42. import java.util.logging.Logger;
  43. /**
  44. * <code>AwtKeyInput</code>
  45. *
  46. * @author Joshua Slack
  47. * @author Kirill Vainer
  48. * @version $Revision: 4133 $
  49. */
  50. public class AwtKeyInput implements KeyInput, KeyListener {
  51. private static final Logger logger = Logger.getLogger(AwtKeyInput.class.getName());
  52. private final ArrayList<KeyInputEvent> eventQueue = new ArrayList<KeyInputEvent>();
  53. private RawInputListener listener;
  54. private Component component;
  55. private BitSet keyStateSet = new BitSet(0xFF);
  56. public AwtKeyInput(){
  57. }
  58. public void initialize() {
  59. }
  60. public void destroy() {
  61. }
  62. public void setInputSource(Component comp){
  63. synchronized (eventQueue){
  64. if (component != null){
  65. component.removeKeyListener(this);
  66. eventQueue.clear();
  67. keyStateSet.clear();
  68. }
  69. component = comp;
  70. component.addKeyListener(this);
  71. }
  72. }
  73. public long getInputTimeNanos() {
  74. return System.nanoTime();
  75. }
  76. public int getKeyCount() {
  77. return KeyEvent.KEY_LAST+1;
  78. }
  79. public void update() {
  80. synchronized (eventQueue){
  81. // flush events to listener
  82. for (int i = 0; i < eventQueue.size(); i++){
  83. listener.onKeyEvent(eventQueue.get(i));
  84. }
  85. eventQueue.clear();
  86. }
  87. }
  88. public boolean isInitialized() {
  89. return true;
  90. }
  91. public void setInputListener(RawInputListener listener) {
  92. this.listener = listener;
  93. }
  94. public void keyTyped(KeyEvent evt) {
  95. // key code is zero for typed events
  96. }
  97. public void keyPressed(KeyEvent evt) {
  98. int code = convertAwtKey(evt.getKeyCode());
  99. // Check if key was already pressed
  100. if (!keyStateSet.get(code)){
  101. keyStateSet.set(code);
  102. KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false);
  103. keyEvent.setTime(evt.getWhen());
  104. synchronized (eventQueue){
  105. eventQueue.add(keyEvent);
  106. }
  107. System.out.println(evt);
  108. }
  109. }
  110. public void keyReleased(KeyEvent evt) {
  111. int code = convertAwtKey(evt.getKeyCode());
  112. // Check if key was already released
  113. if (keyStateSet.get(code)) {
  114. keyStateSet.clear(code);
  115. KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false);
  116. keyEvent.setTime(evt.getWhen());
  117. synchronized (eventQueue){
  118. eventQueue.add(keyEvent);
  119. }
  120. System.out.println(evt);
  121. }
  122. }
  123. /**
  124. * <code>convertJmeCode</code> converts KeyInput key codes to AWT key codes.
  125. *
  126. * @param key jme KeyInput key code
  127. * @return awt KeyEvent key code
  128. */
  129. public static int convertJmeCode( int key ) {
  130. switch ( key ) {
  131. case KEY_ESCAPE:
  132. return KeyEvent.VK_ESCAPE;
  133. case KEY_1:
  134. return KeyEvent.VK_1;
  135. case KEY_2:
  136. return KeyEvent.VK_2;
  137. case KEY_3:
  138. return KeyEvent.VK_3;
  139. case KEY_4:
  140. return KeyEvent.VK_4;
  141. case KEY_5:
  142. return KeyEvent.VK_5;
  143. case KEY_6:
  144. return KeyEvent.VK_6;
  145. case KEY_7:
  146. return KeyEvent.VK_7;
  147. case KEY_8:
  148. return KeyEvent.VK_8;
  149. case KEY_9:
  150. return KeyEvent.VK_9;
  151. case KEY_0:
  152. return KeyEvent.VK_0;
  153. case KEY_MINUS:
  154. return KeyEvent.VK_MINUS;
  155. case KEY_EQUALS:
  156. return KeyEvent.VK_EQUALS;
  157. case KEY_BACK:
  158. return KeyEvent.VK_BACK_SPACE;
  159. case KEY_TAB:
  160. return KeyEvent.VK_TAB;
  161. case KEY_Q:
  162. return KeyEvent.VK_Q;
  163. case KEY_W:
  164. return KeyEvent.VK_W;
  165. case KEY_E:
  166. return KeyEvent.VK_E;
  167. case KEY_R:
  168. return KeyEvent.VK_R;
  169. case KEY_T:
  170. return KeyEvent.VK_T;
  171. case KEY_Y:
  172. return KeyEvent.VK_Y;
  173. case KEY_U:
  174. return KeyEvent.VK_U;
  175. case KEY_I:
  176. return KeyEvent.VK_I;
  177. case KEY_O:
  178. return KeyEvent.VK_O;
  179. case KEY_P:
  180. return KeyEvent.VK_P;
  181. case KEY_LBRACKET:
  182. return KeyEvent.VK_OPEN_BRACKET;
  183. case KEY_RBRACKET:
  184. return KeyEvent.VK_CLOSE_BRACKET;
  185. case KEY_RETURN:
  186. return KeyEvent.VK_ENTER;
  187. case KEY_LCONTROL:
  188. return KeyEvent.VK_CONTROL;
  189. case KEY_A:
  190. return KeyEvent.VK_A;
  191. case KEY_S:
  192. return KeyEvent.VK_S;
  193. case KEY_D:
  194. return KeyEvent.VK_D;
  195. case KEY_F:
  196. return KeyEvent.VK_F;
  197. case KEY_G:
  198. return KeyEvent.VK_G;
  199. case KEY_H:
  200. return KeyEvent.VK_H;
  201. case KEY_J:
  202. return KeyEvent.VK_J;
  203. case KEY_K:
  204. return KeyEvent.VK_K;
  205. case KEY_L:
  206. return KeyEvent.VK_L;
  207. case KEY_SEMICOLON:
  208. return KeyEvent.VK_SEMICOLON;
  209. case KEY_APOSTROPHE:
  210. return KeyEvent.VK_QUOTE;
  211. case KEY_GRAVE:
  212. return KeyEvent.VK_DEAD_GRAVE;
  213. case KEY_LSHIFT:
  214. return KeyEvent.VK_SHIFT;
  215. case KEY_BACKSLASH:
  216. return KeyEvent.VK_BACK_SLASH;
  217. case KEY_Z:
  218. return KeyEvent.VK_Z;
  219. case KEY_X:
  220. return KeyEvent.VK_X;
  221. case KEY_C:
  222. return KeyEvent.VK_C;
  223. case KEY_V:
  224. return KeyEvent.VK_V;
  225. case KEY_B:
  226. return KeyEvent.VK_B;
  227. case KEY_N:
  228. return KeyEvent.VK_N;
  229. case KEY_M:
  230. return KeyEvent.VK_M;
  231. case KEY_COMMA:
  232. return KeyEvent.VK_COMMA;
  233. case KEY_PERIOD:
  234. return KeyEvent.VK_PERIOD;
  235. case KEY_SLASH:
  236. return KeyEvent.VK_SLASH;
  237. case KEY_RSHIFT:
  238. return KeyEvent.VK_SHIFT;
  239. case KEY_MULTIPLY:
  240. return KeyEvent.VK_MULTIPLY;
  241. case KEY_SPACE:
  242. return KeyEvent.VK_SPACE;
  243. case KEY_CAPITAL:
  244. return KeyEvent.VK_CAPS_LOCK;
  245. case KEY_F1:
  246. return KeyEvent.VK_F1;
  247. case KEY_F2:
  248. return KeyEvent.VK_F2;
  249. case KEY_F3:
  250. return KeyEvent.VK_F3;
  251. case KEY_F4:
  252. return KeyEvent.VK_F4;
  253. case KEY_F5:
  254. return KeyEvent.VK_F5;
  255. case KEY_F6:
  256. return KeyEvent.VK_F6;
  257. case KEY_F7:
  258. return KeyEvent.VK_F7;
  259. case KEY_F8:
  260. return KeyEvent.VK_F8;
  261. case KEY_F9:
  262. return KeyEvent.VK_F9;
  263. case KEY_F10:
  264. return KeyEvent.VK_F10;
  265. case KEY_NUMLOCK:
  266. return KeyEvent.VK_NUM_LOCK;
  267. case KEY_SCROLL:
  268. return KeyEvent.VK_SCROLL_LOCK;
  269. case KEY_NUMPAD7:
  270. return KeyEvent.VK_NUMPAD7;
  271. case KEY_NUMPAD8:
  272. return KeyEvent.VK_NUMPAD8;
  273. case KEY_NUMPAD9:
  274. return KeyEvent.VK_NUMPAD9;
  275. case KEY_SUBTRACT:
  276. return KeyEvent.VK_SUBTRACT;
  277. case KEY_NUMPAD4:
  278. return KeyEvent.VK_NUMPAD4;
  279. case KEY_NUMPAD5:
  280. return KeyEvent.VK_NUMPAD5;
  281. case KEY_NUMPAD6:
  282. return KeyEvent.VK_NUMPAD6;
  283. case KEY_ADD:
  284. return KeyEvent.VK_ADD;
  285. case KEY_NUMPAD1:
  286. return KeyEvent.VK_NUMPAD1;
  287. case KEY_NUMPAD2:
  288. return KeyEvent.VK_NUMPAD2;
  289. case KEY_NUMPAD3:
  290. return KeyEvent.VK_NUMPAD3;
  291. case KEY_NUMPAD0:
  292. return KeyEvent.VK_NUMPAD0;
  293. case KEY_DECIMAL:
  294. return KeyEvent.VK_DECIMAL;
  295. case KEY_F11:
  296. return KeyEvent.VK_F11;
  297. case KEY_F12:
  298. return KeyEvent.VK_F12;
  299. case KEY_F13:
  300. return KeyEvent.VK_F13;
  301. case KEY_F14:
  302. return KeyEvent.VK_F14;
  303. case KEY_F15:
  304. return KeyEvent.VK_F15;
  305. case KEY_KANA:
  306. return KeyEvent.VK_KANA;
  307. case KEY_CONVERT:
  308. return KeyEvent.VK_CONVERT;
  309. case KEY_NOCONVERT:
  310. return KeyEvent.VK_NONCONVERT;
  311. case KEY_NUMPADEQUALS:
  312. return KeyEvent.VK_EQUALS;
  313. case KEY_CIRCUMFLEX:
  314. return KeyEvent.VK_CIRCUMFLEX;
  315. case KEY_AT:
  316. return KeyEvent.VK_AT;
  317. case KEY_COLON:
  318. return KeyEvent.VK_COLON;
  319. case KEY_UNDERLINE:
  320. return KeyEvent.VK_UNDERSCORE;
  321. case KEY_STOP:
  322. return KeyEvent.VK_STOP;
  323. case KEY_NUMPADENTER:
  324. return KeyEvent.VK_ENTER;
  325. case KEY_RCONTROL:
  326. return KeyEvent.VK_CONTROL;
  327. case KEY_NUMPADCOMMA:
  328. return KeyEvent.VK_COMMA;
  329. case KEY_DIVIDE:
  330. return KeyEvent.VK_DIVIDE;
  331. case KEY_PAUSE:
  332. return KeyEvent.VK_PAUSE;
  333. case KEY_HOME:
  334. return KeyEvent.VK_HOME;
  335. case KEY_UP:
  336. return KeyEvent.VK_UP;
  337. case KEY_PRIOR:
  338. return KeyEvent.VK_PAGE_UP;
  339. case KEY_LEFT:
  340. return KeyEvent.VK_LEFT;
  341. case KEY_RIGHT:
  342. return KeyEvent.VK_RIGHT;
  343. case KEY_END:
  344. return KeyEvent.VK_END;
  345. case KEY_DOWN:
  346. return KeyEvent.VK_DOWN;
  347. case KEY_NEXT:
  348. return KeyEvent.VK_PAGE_DOWN;
  349. case KEY_INSERT:
  350. return KeyEvent.VK_INSERT;
  351. case KEY_DELETE:
  352. return KeyEvent.VK_DELETE;
  353. case KEY_LMENU:
  354. return KeyEvent.VK_ALT; //todo: location left
  355. case KEY_RMENU:
  356. return KeyEvent.VK_ALT; //todo: location right
  357. }
  358. logger.log(Level.WARNING, "unsupported key:{0}", key);
  359. return 0x10000 + key;
  360. }
  361. /**
  362. * <code>convertAwtKey</code> converts AWT key codes to KeyInput key codes.
  363. *
  364. * @param key awt KeyEvent key code
  365. * @return jme KeyInput key code
  366. */
  367. public static int convertAwtKey(int key) {
  368. switch ( key ) {
  369. case KeyEvent.VK_ESCAPE:
  370. return KEY_ESCAPE;
  371. case KeyEvent.VK_1:
  372. return KEY_1;
  373. case KeyEvent.VK_2:
  374. return KEY_2;
  375. case KeyEvent.VK_3:
  376. return KEY_3;
  377. case KeyEvent.VK_4:
  378. return KEY_4;
  379. case KeyEvent.VK_5:
  380. return KEY_5;
  381. case KeyEvent.VK_6:
  382. return KEY_6;
  383. case KeyEvent.VK_7:
  384. return KEY_7;
  385. case KeyEvent.VK_8:
  386. return KEY_8;
  387. case KeyEvent.VK_9:
  388. return KEY_9;
  389. case KeyEvent.VK_0:
  390. return KEY_0;
  391. case KeyEvent.VK_MINUS:
  392. return KEY_MINUS;
  393. case KeyEvent.VK_EQUALS:
  394. return KEY_EQUALS;
  395. case KeyEvent.VK_BACK_SPACE:
  396. return KEY_BACK;
  397. case KeyEvent.VK_TAB:
  398. return KEY_TAB;
  399. case KeyEvent.VK_Q:
  400. return KEY_Q;
  401. case KeyEvent.VK_W:
  402. return KEY_W;
  403. case KeyEvent.VK_E:
  404. return KEY_E;
  405. case KeyEvent.VK_R:
  406. return KEY_R;
  407. case KeyEvent.VK_T:
  408. return KEY_T;
  409. case KeyEvent.VK_Y:
  410. return KEY_Y;
  411. case KeyEvent.VK_U:
  412. return KEY_U;
  413. case KeyEvent.VK_I:
  414. return KEY_I;
  415. case KeyEvent.VK_O:
  416. return KEY_O;
  417. case KeyEvent.VK_P:
  418. return KEY_P;
  419. case KeyEvent.VK_OPEN_BRACKET:
  420. return KEY_LBRACKET;
  421. case KeyEvent.VK_CLOSE_BRACKET:
  422. return KEY_RBRACKET;
  423. case KeyEvent.VK_ENTER:
  424. return KEY_RETURN;
  425. case KeyEvent.VK_CONTROL:
  426. return KEY_LCONTROL;
  427. case KeyEvent.VK_A:
  428. return KEY_A;
  429. case KeyEvent.VK_S:
  430. return KEY_S;
  431. case KeyEvent.VK_D:
  432. return KEY_D;
  433. case KeyEvent.VK_F:
  434. return KEY_F;
  435. case KeyEvent.VK_G:
  436. return KEY_G;
  437. case KeyEvent.VK_H:
  438. return KEY_H;
  439. case KeyEvent.VK_J:
  440. return KEY_J;
  441. case KeyEvent.VK_K:
  442. return KEY_K;
  443. case KeyEvent.VK_L:
  444. return KEY_L;
  445. case KeyEvent.VK_SEMICOLON:
  446. return KEY_SEMICOLON;
  447. case KeyEvent.VK_QUOTE:
  448. return KEY_APOSTROPHE;
  449. case KeyEvent.VK_DEAD_GRAVE:
  450. return KEY_GRAVE;
  451. case KeyEvent.VK_SHIFT:
  452. return KEY_LSHIFT;
  453. case KeyEvent.VK_BACK_SLASH:
  454. return KEY_BACKSLASH;
  455. case KeyEvent.VK_Z:
  456. return KEY_Z;
  457. case KeyEvent.VK_X:
  458. return KEY_X;
  459. case KeyEvent.VK_C:
  460. return KEY_C;
  461. case KeyEvent.VK_V:
  462. return KEY_V;
  463. case KeyEvent.VK_B:
  464. return KEY_B;
  465. case KeyEvent.VK_N:
  466. return KEY_N;
  467. case KeyEvent.VK_M:
  468. return KEY_M;
  469. case KeyEvent.VK_COMMA:
  470. return KEY_COMMA;
  471. case KeyEvent.VK_PERIOD:
  472. return KEY_PERIOD;
  473. case KeyEvent.VK_SLASH:
  474. return KEY_SLASH;
  475. case KeyEvent.VK_MULTIPLY:
  476. return KEY_MULTIPLY;
  477. case KeyEvent.VK_SPACE:
  478. return KEY_SPACE;
  479. case KeyEvent.VK_CAPS_LOCK:
  480. return KEY_CAPITAL;
  481. case KeyEvent.VK_F1:
  482. return KEY_F1;
  483. case KeyEvent.VK_F2:
  484. return KEY_F2;
  485. case KeyEvent.VK_F3:
  486. return KEY_F3;
  487. case KeyEvent.VK_F4:
  488. return KEY_F4;
  489. case KeyEvent.VK_F5:
  490. return KEY_F5;
  491. case KeyEvent.VK_F6:
  492. return KEY_F6;
  493. case KeyEvent.VK_F7:
  494. return KEY_F7;
  495. case KeyEvent.VK_F8:
  496. return KEY_F8;
  497. case KeyEvent.VK_F9:
  498. return KEY_F9;
  499. case KeyEvent.VK_F10:
  500. return KEY_F10;
  501. case KeyEvent.VK_NUM_LOCK:
  502. return KEY_NUMLOCK;
  503. case KeyEvent.VK_SCROLL_LOCK:
  504. return KEY_SCROLL;
  505. case KeyEvent.VK_NUMPAD7:
  506. return KEY_NUMPAD7;
  507. case KeyEvent.VK_NUMPAD8:
  508. return KEY_NUMPAD8;
  509. case KeyEvent.VK_NUMPAD9:
  510. return KEY_NUMPAD9;
  511. case KeyEvent.VK_SUBTRACT:
  512. return KEY_SUBTRACT;
  513. case KeyEvent.VK_NUMPAD4:
  514. return KEY_NUMPAD4;
  515. case KeyEvent.VK_NUMPAD5:
  516. return KEY_NUMPAD5;
  517. case KeyEvent.VK_NUMPAD6:
  518. return KEY_NUMPAD6;
  519. case KeyEvent.VK_ADD:
  520. return KEY_ADD;
  521. case KeyEvent.VK_NUMPAD1:
  522. return KEY_NUMPAD1;
  523. case KeyEvent.VK_NUMPAD2:
  524. return KEY_NUMPAD2;
  525. case KeyEvent.VK_NUMPAD3:
  526. return KEY_NUMPAD3;
  527. case KeyEvent.VK_NUMPAD0:
  528. return KEY_NUMPAD0;
  529. case KeyEvent.VK_DECIMAL:
  530. return KEY_DECIMAL;
  531. case KeyEvent.VK_F11:
  532. return KEY_F11;
  533. case KeyEvent.VK_F12:
  534. return KEY_F12;
  535. case KeyEvent.VK_F13:
  536. return KEY_F13;
  537. case KeyEvent.VK_F14:
  538. return KEY_F14;
  539. case KeyEvent.VK_F15:
  540. return KEY_F15;
  541. case KeyEvent.VK_KANA:
  542. return KEY_KANA;
  543. case KeyEvent.VK_CONVERT:
  544. return KEY_CONVERT;
  545. case KeyEvent.VK_NONCONVERT:
  546. return KEY_NOCONVERT;
  547. case KeyEvent.VK_CIRCUMFLEX:
  548. return KEY_CIRCUMFLEX;
  549. case KeyEvent.VK_AT:
  550. return KEY_AT;
  551. case KeyEvent.VK_COLON:
  552. return KEY_COLON;
  553. case KeyEvent.VK_UNDERSCORE:
  554. return KEY_UNDERLINE;
  555. case KeyEvent.VK_STOP:
  556. return KEY_STOP;
  557. case KeyEvent.VK_DIVIDE:
  558. return KEY_DIVIDE;
  559. case KeyEvent.VK_PAUSE:
  560. return KEY_PAUSE;
  561. case KeyEvent.VK_HOME:
  562. return KEY_HOME;
  563. case KeyEvent.VK_UP:
  564. return KEY_UP;
  565. case KeyEvent.VK_PAGE_UP:
  566. return KEY_PRIOR;
  567. case KeyEvent.VK_LEFT:
  568. return KEY_LEFT;
  569. case KeyEvent.VK_RIGHT:
  570. return KEY_RIGHT;
  571. case KeyEvent.VK_END:
  572. return KEY_END;
  573. case KeyEvent.VK_DOWN:
  574. return KEY_DOWN;
  575. case KeyEvent.VK_PAGE_DOWN:
  576. return KEY_NEXT;
  577. case KeyEvent.VK_INSERT:
  578. return KEY_INSERT;
  579. case KeyEvent.VK_DELETE:
  580. return KEY_DELETE;
  581. case KeyEvent.VK_ALT:
  582. return KEY_LMENU; //Left vs. Right need to improve
  583. case KeyEvent.VK_META:
  584. return KEY_RCONTROL;
  585. }
  586. logger.log( Level.WARNING, "unsupported key:{0}", key);
  587. if ( key >= 0x10000 ) {
  588. return key - 0x10000;
  589. }
  590. return 0;
  591. }
  592. }