PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/com/melloware/jintellitype/JIntellitype.java

https://bitbucket.org/chuajiesheng/beefree
Java | 645 lines | 428 code | 42 blank | 175 comment | 43 complexity | 8037e1a5fda3fcd893665a2bb41780c5 MD5 | raw file
  1. /**
  2. * JIntellitype ----------------- Copyright 2005-2008 Emil A. Lefkof III,
  3. * Melloware Inc. I always give it my best shot to make a program useful and
  4. * solid, but remeber that there is absolutely no warranty for using this
  5. * program as stated in the following terms: Licensed under the Apache License,
  6. * Version 2.0 (the "License"); you may not use this file except in compliance
  7. * with the License. You may obtain a copy of the License at
  8. * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
  9. * or agreed to in writing, software distributed under the License is
  10. * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  11. * KIND, either express or implied. See the License for the specific language
  12. * governing permissions and limitations under the License.
  13. */
  14. package com.melloware.jintellitype;
  15. import java.awt.event.InputEvent;
  16. import java.awt.event.KeyEvent;
  17. import java.io.File;
  18. import java.io.FileOutputStream;
  19. import java.io.IOException;
  20. import java.io.InputStream;
  21. import java.io.OutputStream;
  22. import java.util.Collections;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.concurrent.CopyOnWriteArrayList;
  26. import javax.swing.SwingUtilities;
  27. /**
  28. * JIntellitype A Java Implementation for using the Windows API Intellitype commands and the RegisterHotKey and
  29. * UnRegisterHotkey API calls for globally responding to key events. Intellitype are commands that are using for Play,
  30. * Stop, Next on Media keyboards or some laptops that have those special keys.
  31. * <p>
  32. * JIntellitype class that is used to call Windows API calls using the JIntellitype.dll.
  33. * <p>
  34. * This file comes with native code in JINTELLITYPE.DLL The DLL should go in C:/WINDOWS/SYSTEM or in your current
  35. * directory
  36. * <p>
  37. * <p>
  38. * Copyright (c) 1999-2008 Melloware, Inc. <http://www.melloware.com>
  39. * @author Emil A. Lefkof III <info@melloware.com>
  40. * @version 1.3.1
  41. */
  42. public final class JIntellitype implements JIntellitypeConstants {
  43. /**
  44. * Static variable to hold singleton.
  45. */
  46. private static JIntellitype jintellitype = null;
  47. /**
  48. * Static variable for double checked thread safety.
  49. */
  50. private static boolean isInitialized = false;
  51. /**
  52. * Static variable to hold the libary location if set
  53. */
  54. private static String libraryLocation = null;
  55. /**
  56. * Listeners collection for Hotkey events
  57. */
  58. private final List<HotkeyListener> hotkeyListeners = Collections.synchronizedList(new CopyOnWriteArrayList<HotkeyListener>());
  59. /**
  60. * Listeners collection for Hotkey events
  61. */
  62. private final List<IntellitypeListener> intellitypeListeners = Collections.synchronizedList(new CopyOnWriteArrayList<IntellitypeListener>());
  63. /**
  64. * Handler is used by JNI code to keep different JVM instances separate
  65. */
  66. private final int handler = 0;
  67. /**
  68. * Map containing key->keycode mapping
  69. * @see #registerHotKey(int, String)
  70. * @see #getKey2KeycodeMapping()
  71. */
  72. private final HashMap<String, Integer> keycodeMap;
  73. /**
  74. * Private Constructor to prevent instantiation. Initialize the library for calling.
  75. */
  76. private JIntellitype() {
  77. try {
  78. // Load JNI library
  79. System.loadLibrary("JIntellitype");
  80. } catch (Throwable ex) {
  81. try {
  82. if (getLibraryLocation() != null) {
  83. System.load(getLibraryLocation());
  84. } else {
  85. String jarPath = "com/melloware/jintellitype/";
  86. String tmpDir = System.getProperty("java.io.tmpdir");
  87. try {
  88. String dll = "JIntellitype.dll";
  89. fromJarToFs(jarPath + dll, tmpDir + dll);
  90. System.load(tmpDir + dll);
  91. } catch (UnsatisfiedLinkError e) {
  92. String dll = "JIntellitype64.dll";
  93. fromJarToFs(jarPath + dll, tmpDir + dll);
  94. System.load(tmpDir + dll);
  95. }
  96. }
  97. } catch (Throwable ex2) {
  98. throw new JIntellitypeException("Could not load JIntellitype.dll from local file system or from inside JAR", ex2);
  99. }
  100. }
  101. initializeLibrary();
  102. this.keycodeMap = getKey2KeycodeMapping();
  103. }
  104. /**
  105. * Pulls a file out of the JAR and puts it on the File Path.
  106. * <p>
  107. * @param jarPath the path to the JAR
  108. * @param filePath the file path to extract to
  109. * @throws IOException if any IO error occurs
  110. */
  111. private void fromJarToFs(String jarPath, String filePath) throws IOException {
  112. File file = new File(filePath);
  113. if (file.exists()) {
  114. boolean success = file.delete();
  115. if (!success) {
  116. throw new IOException("couldn't delete " + filePath);
  117. }
  118. }
  119. InputStream is = null;
  120. OutputStream os = null;
  121. try {
  122. is = ClassLoader.getSystemClassLoader().getResourceAsStream(jarPath);
  123. os = new FileOutputStream(filePath);
  124. byte[] buffer = new byte[8192];
  125. int bytesRead;
  126. while ((bytesRead = is.read(buffer)) != -1) {
  127. os.write(buffer, 0, bytesRead);
  128. }
  129. } finally {
  130. if (is != null) {
  131. is.close();
  132. }
  133. if (os != null) {
  134. os.close();
  135. }
  136. }
  137. }
  138. /**
  139. * Gets the singleton instance of the JIntellitype object.
  140. * <p>
  141. * But the possibility of creation of more instance is only before the instance is created. Since all code defined
  142. * inside getInstance method is in the synchronized block, even the subsequent requests will also come and wait in
  143. * the synchronized block. This is a performance issue. The same can be solved using double-checked lock. Following
  144. * is the implementation of Singleton with lazy initialization and double-checked lock.
  145. * <p>
  146. * @return an instance of JIntellitype class
  147. */
  148. public static JIntellitype getInstance() {
  149. if (!isInitialized) {
  150. synchronized (JIntellitype.class) {
  151. if (!isInitialized) {
  152. jintellitype = new JIntellitype();
  153. isInitialized = true;
  154. }
  155. }
  156. }
  157. return jintellitype;
  158. }
  159. /**
  160. * Adds a listener for hotkeys.
  161. * <p>
  162. * @param listener the HotKeyListener to be added
  163. */
  164. public void addHotKeyListener(HotkeyListener listener) {
  165. hotkeyListeners.add(listener);
  166. }
  167. /**
  168. * Adds a listener for intellitype commands.
  169. * <p>
  170. * @param listener the IntellitypeListener to be added
  171. */
  172. public void addIntellitypeListener(IntellitypeListener listener) {
  173. intellitypeListeners.add(listener);
  174. }
  175. /**
  176. * Cleans up all resources used by JIntellitype.
  177. */
  178. public void cleanUp() {
  179. try {
  180. terminate();
  181. } catch (UnsatisfiedLinkError ex) {
  182. throw new JIntellitypeException(ERROR_MESSAGE, ex);
  183. } catch (RuntimeException ex) {
  184. throw new JIntellitypeException(ex);
  185. }
  186. }
  187. /**
  188. * Registers a Hotkey with windows. This combination will be responded to by all registered HotKeyListeners. Uses the
  189. * JIntellitypeConstants for MOD, ALT, CTRL, and WINDOWS keys.
  190. * <p>
  191. * @param identifier a unique identifier for this key combination
  192. * @param modifier MOD_SHIFT, MOD_ALT, MOD_CONTROL, MOD_WIN from JIntellitypeConstants, or 0 if no modifier needed
  193. * @param keycode the key to respond to in Ascii integer, 65 for A
  194. */
  195. public void registerHotKey(int identifier, int modifier, int keycode) {
  196. try {
  197. int modifiers = swingToIntelliType(modifier);
  198. if (modifiers == 0) {
  199. modifiers = modifier;
  200. }
  201. regHotKey(identifier, modifier, keycode);
  202. } catch (UnsatisfiedLinkError ex) {
  203. throw new JIntellitypeException(ERROR_MESSAGE, ex);
  204. } catch (RuntimeException ex) {
  205. throw new JIntellitypeException(ex);
  206. }
  207. }
  208. /**
  209. * Registers a Hotkey with windows. This combination will be responded to by all registered HotKeyListeners. Use the
  210. * Swing InputEvent constants from java.awt.InputEvent.
  211. * <p>
  212. * @param identifier a unique identifier for this key combination
  213. * @param modifier InputEvent.SHIFT_MASK, InputEvent.ALT_MASK, InputEvent.CTRL_MASK, or 0 if no modifier needed
  214. * @param keycode the key to respond to in Ascii integer, 65 for A
  215. */
  216. public void registerSwingHotKey(int identifier, int modifier, int keycode) {
  217. try {
  218. regHotKey(identifier, swingToIntelliType(modifier), keycode);
  219. } catch (UnsatisfiedLinkError ex) {
  220. throw new JIntellitypeException(ERROR_MESSAGE, ex);
  221. } catch (RuntimeException ex) {
  222. throw new JIntellitypeException(ex);
  223. }
  224. }
  225. /**
  226. * Registers a Hotkey with windows. This combination will be responded to by all registered HotKeyListeners. Use the
  227. * identifiers CTRL, SHIFT, ALT and/or WIN.
  228. * <p>
  229. * @param identifier a unique identifier for this key combination
  230. * @param modifierAndKeyCode String with modifiers separated by + and keycode (e.g. CTRL+SHIFT+A)
  231. * @see #registerHotKey(int, int, int)
  232. * @see #registerSwingHotKey(int, int, int)
  233. */
  234. public void registerHotKey(int identifier, String modifierAndKeyCode) {
  235. String[] split = modifierAndKeyCode.split("\\+");
  236. int mask = 0;
  237. int keycode = 0;
  238. for (int i = 0; i < split.length; i++) {
  239. if ("ALT".equalsIgnoreCase(split[i])) {
  240. mask += JIntellitype.MOD_ALT;
  241. } else if ("CTRL".equalsIgnoreCase(split[i]) || "CONTROL".equalsIgnoreCase(split[i])) {
  242. mask += JIntellitype.MOD_CONTROL;
  243. } else if ("SHIFT".equalsIgnoreCase(split[i])) {
  244. mask += JIntellitype.MOD_SHIFT;
  245. } else if ("WIN".equalsIgnoreCase(split[i])) {
  246. mask += JIntellitype.MOD_WIN;
  247. } else if (keycodeMap.containsKey(split[i].toLowerCase())) {
  248. keycode = keycodeMap.get(split[i].toLowerCase());
  249. }
  250. }
  251. registerHotKey(identifier, mask, keycode);
  252. }
  253. /**
  254. * Removes a listener for hotkeys.
  255. */
  256. public void removeHotKeyListener(HotkeyListener listener) {
  257. hotkeyListeners.remove(listener);
  258. }
  259. /**
  260. * Removes a listener for intellitype commands.
  261. */
  262. public void removeIntellitypeListener(IntellitypeListener listener) {
  263. intellitypeListeners.remove(listener);
  264. }
  265. /**
  266. * Unregisters a previously registered Hotkey identified by its unique identifier.
  267. * <p>
  268. * @param identifier the unique identifer of this Hotkey
  269. */
  270. public void unregisterHotKey(int identifier) {
  271. try {
  272. unregHotKey(identifier);
  273. } catch (UnsatisfiedLinkError ex) {
  274. throw new JIntellitypeException(ERROR_MESSAGE, ex);
  275. } catch (RuntimeException ex) {
  276. throw new JIntellitypeException(ex);
  277. }
  278. }
  279. /**
  280. * Checks to see if this application is already running.
  281. * <p>
  282. * @param appTitle the name of the application to check for
  283. * @return true if running, false if not running
  284. */
  285. public static boolean checkInstanceAlreadyRunning(String appTitle) {
  286. return getInstance().isRunning(appTitle);
  287. }
  288. /**
  289. * Checks to make sure the OS is a Windows flavor and that the JIntellitype DLL is found in the path and the JDK is
  290. * 32 bit not 64 bit. The DLL currently only supports 32 bit JDK.
  291. * <p>
  292. * @return true if Jintellitype may be used, false if not
  293. */
  294. public static boolean isJIntellitypeSupported() {
  295. boolean result = false;
  296. String os = "none";
  297. try {
  298. os = System.getProperty("os.name").toLowerCase();
  299. } catch (SecurityException ex) {
  300. // we are not allowed to look at this property
  301. System.err.println("Caught a SecurityException reading the system property " + "'os.name'; the SystemUtils property value will default to null.");
  302. }
  303. // only works on Windows OS currently
  304. if (os.startsWith("windows")) {
  305. // try an get the instance and if it succeeds then return true
  306. try {
  307. getInstance();
  308. result = true;
  309. } catch (Exception e) {
  310. result = false;
  311. }
  312. }
  313. return result;
  314. }
  315. /**
  316. * Gets the libraryLocation.
  317. * <p>
  318. * @return Returns the libraryLocation.
  319. */
  320. public static String getLibraryLocation() {
  321. return libraryLocation;
  322. }
  323. /**
  324. * Sets the libraryLocation.
  325. * <p>
  326. * @param libraryLocation The libraryLocation to set.
  327. */
  328. public static void setLibraryLocation(String libraryLocation) {
  329. final File dll = new File(libraryLocation);
  330. if (!dll.isAbsolute()) {
  331. JIntellitype.libraryLocation = dll.getAbsolutePath();
  332. } else {
  333. // absolute path, no further calculation needed
  334. JIntellitype.libraryLocation = libraryLocation;
  335. }
  336. }
  337. /**
  338. * Notifies all listeners that Hotkey was pressed.
  339. * <p>
  340. * @param identifier the unique identifier received
  341. */
  342. protected void onHotKey(final int identifier) {
  343. for (final HotkeyListener hotkeyListener : hotkeyListeners) {
  344. SwingUtilities.invokeLater(new Runnable() {
  345. public void run() {
  346. hotkeyListener.onHotKey(identifier);
  347. }
  348. });
  349. }
  350. }
  351. /**
  352. * Notifies all listeners that Intellitype command was received.
  353. * <p>
  354. * @param command the unique WM_APPCOMMAND received
  355. */
  356. protected void onIntellitype(final int command) {
  357. for (final IntellitypeListener intellitypeListener : intellitypeListeners) {
  358. SwingUtilities.invokeLater(new Runnable() {
  359. public void run() {
  360. intellitypeListener.onIntellitype(command);
  361. }
  362. });
  363. }
  364. }
  365. /**
  366. * Swing modifier value to Jintellipad conversion. If no conversion needed just return the original value. This lets
  367. * users pass either the original JIntellitype constants or Swing InputEvent constants.
  368. * <p>
  369. * @param swingKeystrokeModifier the Swing KeystrokeModifier to check
  370. * @return Jintellitype the JIntellitype modifier value
  371. */
  372. protected static int swingToIntelliType(int swingKeystrokeModifier) {
  373. int mask = 0;
  374. if ((swingKeystrokeModifier & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) {
  375. mask &= JIntellitype.MOD_SHIFT;
  376. }
  377. if ((swingKeystrokeModifier & InputEvent.ALT_MASK) == InputEvent.ALT_MASK) {
  378. mask &= JIntellitype.MOD_ALT;
  379. }
  380. if ((swingKeystrokeModifier & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
  381. mask &= JIntellitype.MOD_CONTROL;
  382. }
  383. if ((swingKeystrokeModifier & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
  384. mask &= JIntellitype.MOD_SHIFT;
  385. }
  386. if ((swingKeystrokeModifier & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK) {
  387. mask &= JIntellitype.MOD_ALT;
  388. }
  389. if ((swingKeystrokeModifier & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
  390. mask &= JIntellitype.MOD_CONTROL;
  391. }
  392. return mask;
  393. }
  394. /**
  395. * Puts all constants from {@link java.awt.event.KeyEvent} in a keycodeMap. The key is the lower case form of it.
  396. * @return Map containing key->keycode mapping DOCU Now enables the user to use all keys specified here instead of
  397. * just [A-Z],[0-9] as before
  398. */
  399. private HashMap<String, Integer> getKey2KeycodeMapping() {
  400. HashMap<String, Integer> map = new HashMap<String, Integer>();
  401. map.put("first", KeyEvent.KEY_FIRST);
  402. map.put("last", KeyEvent.KEY_LAST);
  403. map.put("typed", KeyEvent.KEY_TYPED);
  404. map.put("pressed", KeyEvent.KEY_PRESSED);
  405. map.put("released", KeyEvent.KEY_RELEASED);
  406. map.put("enter", 13);
  407. map.put("back_space", KeyEvent.VK_BACK_SPACE);
  408. map.put("tab", KeyEvent.VK_TAB);
  409. map.put("cancel", KeyEvent.VK_CANCEL);
  410. map.put("clear", KeyEvent.VK_CLEAR);
  411. map.put("pause", KeyEvent.VK_PAUSE);
  412. map.put("caps_lock", KeyEvent.VK_CAPS_LOCK);
  413. map.put("escape", KeyEvent.VK_ESCAPE);
  414. map.put("space", KeyEvent.VK_SPACE);
  415. map.put("page_up", KeyEvent.VK_PAGE_UP);
  416. map.put("page_down", KeyEvent.VK_PAGE_DOWN);
  417. map.put("end", KeyEvent.VK_END);
  418. map.put("home", KeyEvent.VK_HOME);
  419. map.put("left", KeyEvent.VK_LEFT);
  420. map.put("up", KeyEvent.VK_UP);
  421. map.put("right", KeyEvent.VK_RIGHT);
  422. map.put("down", KeyEvent.VK_DOWN);
  423. map.put("comma", 188);
  424. map.put("minus", 109);
  425. map.put("period", 110);
  426. map.put("slash", 191);
  427. map.put("accent `", 192);
  428. map.put("0", KeyEvent.VK_0);
  429. map.put("1", KeyEvent.VK_1);
  430. map.put("2", KeyEvent.VK_2);
  431. map.put("3", KeyEvent.VK_3);
  432. map.put("4", KeyEvent.VK_4);
  433. map.put("5", KeyEvent.VK_5);
  434. map.put("6", KeyEvent.VK_6);
  435. map.put("7", KeyEvent.VK_7);
  436. map.put("8", KeyEvent.VK_8);
  437. map.put("9", KeyEvent.VK_9);
  438. map.put("semicolon", 186);
  439. map.put("equals", 187);
  440. map.put("a", KeyEvent.VK_A);
  441. map.put("b", KeyEvent.VK_B);
  442. map.put("c", KeyEvent.VK_C);
  443. map.put("d", KeyEvent.VK_D);
  444. map.put("e", KeyEvent.VK_E);
  445. map.put("f", KeyEvent.VK_F);
  446. map.put("g", KeyEvent.VK_G);
  447. map.put("h", KeyEvent.VK_H);
  448. map.put("i", KeyEvent.VK_I);
  449. map.put("j", KeyEvent.VK_J);
  450. map.put("k", KeyEvent.VK_K);
  451. map.put("l", KeyEvent.VK_L);
  452. map.put("m", KeyEvent.VK_M);
  453. map.put("n", KeyEvent.VK_N);
  454. map.put("o", KeyEvent.VK_O);
  455. map.put("p", KeyEvent.VK_P);
  456. map.put("q", KeyEvent.VK_Q);
  457. map.put("r", KeyEvent.VK_R);
  458. map.put("s", KeyEvent.VK_S);
  459. map.put("t", KeyEvent.VK_T);
  460. map.put("u", KeyEvent.VK_U);
  461. map.put("v", KeyEvent.VK_V);
  462. map.put("w", KeyEvent.VK_W);
  463. map.put("x", KeyEvent.VK_X);
  464. map.put("y", KeyEvent.VK_Y);
  465. map.put("z", KeyEvent.VK_Z);
  466. map.put("open_bracket", 219);
  467. map.put("back_slash", 220);
  468. map.put("close_bracket", 221);
  469. map.put("numpad0", KeyEvent.VK_NUMPAD0);
  470. map.put("numpad1", KeyEvent.VK_NUMPAD1);
  471. map.put("numpad2", KeyEvent.VK_NUMPAD2);
  472. map.put("numpad3", KeyEvent.VK_NUMPAD3);
  473. map.put("numpad4", KeyEvent.VK_NUMPAD4);
  474. map.put("numpad5", KeyEvent.VK_NUMPAD5);
  475. map.put("numpad6", KeyEvent.VK_NUMPAD6);
  476. map.put("numpad7", KeyEvent.VK_NUMPAD7);
  477. map.put("numpad8", KeyEvent.VK_NUMPAD8);
  478. map.put("numpad9", KeyEvent.VK_NUMPAD9);
  479. map.put("multiply", KeyEvent.VK_MULTIPLY);
  480. map.put("add", KeyEvent.VK_ADD);
  481. map.put("separator", KeyEvent.VK_SEPARATOR);
  482. map.put("subtract", KeyEvent.VK_SUBTRACT);
  483. map.put("decimal", KeyEvent.VK_DECIMAL);
  484. map.put("divide", KeyEvent.VK_DIVIDE);
  485. map.put("delete", 46);
  486. map.put("num_lock", KeyEvent.VK_NUM_LOCK);
  487. map.put("scroll_lock", KeyEvent.VK_SCROLL_LOCK);
  488. map.put("f1", KeyEvent.VK_F1);
  489. map.put("f2", KeyEvent.VK_F2);
  490. map.put("f3", KeyEvent.VK_F3);
  491. map.put("f4", KeyEvent.VK_F4);
  492. map.put("f5", KeyEvent.VK_F5);
  493. map.put("f6", KeyEvent.VK_F6);
  494. map.put("f7", KeyEvent.VK_F7);
  495. map.put("f8", KeyEvent.VK_F8);
  496. map.put("f9", KeyEvent.VK_F9);
  497. map.put("f10", KeyEvent.VK_F10);
  498. map.put("f11", KeyEvent.VK_F11);
  499. map.put("f12", KeyEvent.VK_F12);
  500. map.put("f13", KeyEvent.VK_F13);
  501. map.put("f14", KeyEvent.VK_F14);
  502. map.put("f15", KeyEvent.VK_F15);
  503. map.put("f16", KeyEvent.VK_F16);
  504. map.put("f17", KeyEvent.VK_F17);
  505. map.put("f18", KeyEvent.VK_F18);
  506. map.put("f19", KeyEvent.VK_F19);
  507. map.put("f20", KeyEvent.VK_F20);
  508. map.put("f21", KeyEvent.VK_F21);
  509. map.put("f22", KeyEvent.VK_F22);
  510. map.put("f23", KeyEvent.VK_F23);
  511. map.put("f24", KeyEvent.VK_F24);
  512. map.put("printscreen", 44);
  513. map.put("insert", 45);
  514. map.put("help", 47);
  515. map.put("meta", KeyEvent.VK_META);
  516. map.put("back_quote", KeyEvent.VK_BACK_QUOTE);
  517. map.put("quote", KeyEvent.VK_QUOTE);
  518. map.put("kp_up", KeyEvent.VK_KP_UP);
  519. map.put("kp_down", KeyEvent.VK_KP_DOWN);
  520. map.put("kp_left", KeyEvent.VK_KP_LEFT);
  521. map.put("kp_right", KeyEvent.VK_KP_RIGHT);
  522. map.put("dead_grave", KeyEvent.VK_DEAD_GRAVE);
  523. map.put("dead_acute", KeyEvent.VK_DEAD_ACUTE);
  524. map.put("dead_circumflex", KeyEvent.VK_DEAD_CIRCUMFLEX);
  525. map.put("dead_tilde", KeyEvent.VK_DEAD_TILDE);
  526. map.put("dead_macron", KeyEvent.VK_DEAD_MACRON);
  527. map.put("dead_breve", KeyEvent.VK_DEAD_BREVE);
  528. map.put("dead_abovedot", KeyEvent.VK_DEAD_ABOVEDOT);
  529. map.put("dead_diaeresis", KeyEvent.VK_DEAD_DIAERESIS);
  530. map.put("dead_abovering", KeyEvent.VK_DEAD_ABOVERING);
  531. map.put("dead_doubleacute", KeyEvent.VK_DEAD_DOUBLEACUTE);
  532. map.put("dead_caron", KeyEvent.VK_DEAD_CARON);
  533. map.put("dead_cedilla", KeyEvent.VK_DEAD_CEDILLA);
  534. map.put("dead_ogonek", KeyEvent.VK_DEAD_OGONEK);
  535. map.put("dead_iota", KeyEvent.VK_DEAD_IOTA);
  536. map.put("dead_voiced_sound", KeyEvent.VK_DEAD_VOICED_SOUND);
  537. map.put("dead_semivoiced_sound", KeyEvent.VK_DEAD_SEMIVOICED_SOUND);
  538. map.put("ampersand", KeyEvent.VK_AMPERSAND);
  539. map.put("asterisk", KeyEvent.VK_ASTERISK);
  540. map.put("quotedbl", KeyEvent.VK_QUOTEDBL);
  541. map.put("less", KeyEvent.VK_LESS);
  542. map.put("greater", KeyEvent.VK_GREATER);
  543. map.put("braceleft", KeyEvent.VK_BRACELEFT);
  544. map.put("braceright", KeyEvent.VK_BRACERIGHT);
  545. map.put("at", KeyEvent.VK_AT);
  546. map.put("colon", KeyEvent.VK_COLON);
  547. map.put("circumflex", KeyEvent.VK_CIRCUMFLEX);
  548. map.put("dollar", KeyEvent.VK_DOLLAR);
  549. map.put("euro_sign", KeyEvent.VK_EURO_SIGN);
  550. map.put("exclamation_mark", KeyEvent.VK_EXCLAMATION_MARK);
  551. map.put("inverted_exclamation_mark", KeyEvent.VK_INVERTED_EXCLAMATION_MARK);
  552. map.put("left_parenthesis", KeyEvent.VK_LEFT_PARENTHESIS);
  553. map.put("number_sign", KeyEvent.VK_NUMBER_SIGN);
  554. map.put("plus", KeyEvent.VK_PLUS);
  555. map.put("right_parenthesis", KeyEvent.VK_RIGHT_PARENTHESIS);
  556. map.put("underscore", KeyEvent.VK_UNDERSCORE);
  557. map.put("context_menu", KeyEvent.VK_CONTEXT_MENU);
  558. map.put("final", KeyEvent.VK_FINAL);
  559. map.put("convert", KeyEvent.VK_CONVERT);
  560. map.put("nonconvert", KeyEvent.VK_NONCONVERT);
  561. map.put("accept", KeyEvent.VK_ACCEPT);
  562. map.put("modechange", KeyEvent.VK_MODECHANGE);
  563. map.put("kana", KeyEvent.VK_KANA);
  564. map.put("kanji", KeyEvent.VK_KANJI);
  565. map.put("alphanumeric", KeyEvent.VK_ALPHANUMERIC);
  566. map.put("katakana", KeyEvent.VK_KATAKANA);
  567. map.put("hiragana", KeyEvent.VK_HIRAGANA);
  568. map.put("full_width", KeyEvent.VK_FULL_WIDTH);
  569. map.put("half_width", KeyEvent.VK_HALF_WIDTH);
  570. map.put("roman_characters", KeyEvent.VK_ROMAN_CHARACTERS);
  571. map.put("all_candidates", KeyEvent.VK_ALL_CANDIDATES);
  572. map.put("previous_candidate", KeyEvent.VK_PREVIOUS_CANDIDATE);
  573. map.put("code_input", KeyEvent.VK_CODE_INPUT);
  574. map.put("japanese_katakana", KeyEvent.VK_JAPANESE_KATAKANA);
  575. map.put("japanese_hiragana", KeyEvent.VK_JAPANESE_HIRAGANA);
  576. map.put("japanese_roman", KeyEvent.VK_JAPANESE_ROMAN);
  577. map.put("kana_lock", KeyEvent.VK_KANA_LOCK);
  578. map.put("input_method_on_off", KeyEvent.VK_INPUT_METHOD_ON_OFF);
  579. map.put("cut", KeyEvent.VK_CUT);
  580. map.put("copy", KeyEvent.VK_COPY);
  581. map.put("paste", KeyEvent.VK_PASTE);
  582. map.put("undo", KeyEvent.VK_UNDO);
  583. map.put("again", KeyEvent.VK_AGAIN);
  584. map.put("find", KeyEvent.VK_FIND);
  585. map.put("props", KeyEvent.VK_PROPS);
  586. map.put("stop", KeyEvent.VK_STOP);
  587. map.put("compose", KeyEvent.VK_COMPOSE);
  588. map.put("alt_graph", KeyEvent.VK_ALT_GRAPH);
  589. map.put("begin", KeyEvent.VK_BEGIN);
  590. return map;
  591. }
  592. private synchronized native void initializeLibrary() throws UnsatisfiedLinkError;
  593. private synchronized native void regHotKey(int identifier, int modifier, int keycode) throws UnsatisfiedLinkError;
  594. private synchronized native void terminate() throws UnsatisfiedLinkError;
  595. private synchronized native void unregHotKey(int identifier) throws UnsatisfiedLinkError;
  596. /**
  597. * Checks if there's an instance with hidden window title = appName running Can be used to detect that another
  598. * instance of your app is already running (so exit..)
  599. * <p>
  600. * @param appName = the title of the hidden window to search for
  601. */
  602. private synchronized native boolean isRunning(String appName);
  603. }