+ * Copyright (c) 1999-2008
+ * Melloware, Inc.
+ * @param identifier the unique Identifer the Hotkey was assigned
+ */
+ void onHotKey( int identifier );
+}
\ No newline at end of file
diff --git a/src/main/java/com/melloware/jintellitype/IntellitypeListener.java b/src/main/java/com/melloware/jintellitype/IntellitypeListener.java
new file mode 100644
index 0000000..4fa5ede
--- /dev/null
+++ b/src/main/java/com/melloware/jintellitype/IntellitypeListener.java
@@ -0,0 +1,51 @@
+/**
+ * JIntellitype
+ * -----------------
+ * Copyright 2005-2008 Emil A. Lefkof III, Melloware Inc.
+ *
+ * I always give it my best shot to make a program useful and solid, but
+ * remeber that there is absolutely no warranty for using this program as
+ * stated in the following terms:
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.melloware.jintellitype;
+
+
+/**
+ * Listener interface for Windows Intellitype events. Intellitype are Windows
+ * App Commands that are specialand were introduced with Microsoft Keyboards
+ * that had special keys for Play, Pause, Stop, Next etc for controlling
+ * Media applications like Windows Media Player, Itunes, and Winamp.
+ *
+ * If you have ever wanted your Swing/SWT application to respond to these global
+ * events you now can with JIntellitype. Just implement this interface and
+ * you can now take action when those special Media keys are pressed.
+ *
+ * Copyright (c) 1999-2008
+ * Melloware, Inc.
+ * @param command the WM_APPCOMMAND that was pressed
+ */
+ void onIntellitype( int command );
+}
\ No newline at end of file
diff --git a/src/main/java/com/melloware/jintellitype/JIntellitype.java b/src/main/java/com/melloware/jintellitype/JIntellitype.java
new file mode 100644
index 0000000..9b348a6
--- /dev/null
+++ b/src/main/java/com/melloware/jintellitype/JIntellitype.java
@@ -0,0 +1,663 @@
+/**
+ * JIntellitype ----------------- Copyright 2005-2008 Emil A. Lefkof III,
+ * Melloware Inc. I always give it my best shot to make a program useful and
+ * solid, but remeber that there is absolutely no warranty for using this
+ * program as stated in the following terms: Licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.melloware.jintellitype;
+
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.swing.SwingUtilities;
+
+/**
+ * JIntellitype A Java Implementation for using the Windows API Intellitype
+ * commands and the RegisterHotKey and UnRegisterHotkey API calls for globally
+ * responding to key events. Intellitype are commands that are using for Play,
+ * Stop, Next on Media keyboards or some laptops that have those special keys.
+ *
+ * JIntellitype class that is used to call Windows API calls using the
+ * JIntellitype.dll.
+ *
+ * This file comes with native code in JINTELLITYPE.DLL The DLL should go in
+ * C:/WINDOWS/SYSTEM or in your current directory
+ *
+ *
+ * Copyright (c) 1999-2008 Melloware, Inc.
+ * @param jarPath the path to the JAR
+ * @param filePath the file path to extract to
+ * @throws IOException if any IO error occurs
+ */
+ private void fromJarToFs(String jarPath, String filePath) throws IOException {
+ File file = new File(filePath);
+ if (file.exists()) {
+ boolean success = file.delete();
+ if (!success) {
+ throw new IOException("couldn't delete " + filePath);
+ }
+ }
+ InputStream is = null;
+ OutputStream os = null;
+ try {
+ is = ClassLoader.getSystemClassLoader().getResourceAsStream(jarPath);
+ os = new FileOutputStream(filePath);
+ byte[] buffer = new byte[8192];
+ int bytesRead;
+ while ((bytesRead = is.read(buffer)) != -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ if (os != null) {
+ os.close();
+ }
+ }
+ }
+
+ /**
+ * Gets the singleton instance of the JIntellitype object.
+ *
+ * But the possibility of creation of more instance is only before the
+ * instance is created. Since all code defined inside getInstance method is
+ * in the synchronized block, even the subsequent requests will also come and
+ * wait in the synchronized block. This is a performance issue. The same can
+ * be solved using double-checked lock. Following is the implementation of
+ * Singleton with lazy initialization and double-checked lock.
+ *
+ * @return an instance of JIntellitype class
+ */
+ public static JIntellitype getInstance() {
+ if (!isInitialized) {
+ synchronized (JIntellitype.class) {
+ if (!isInitialized) {
+ jintellitype = new JIntellitype();
+ isInitialized = true;
+ }
+ }
+ }
+ return jintellitype;
+ }
+
+ /**
+ * Adds a listener for hotkeys.
+ *
+ * @param listener the HotKeyListener to be added
+ */
+ public void addHotKeyListener(HotkeyListener listener) {
+ hotkeyListeners.add(listener);
+ }
+
+ /**
+ * Adds a listener for intellitype commands.
+ *
+ * @param listener the IntellitypeListener to be added
+ */
+ public void addIntellitypeListener(IntellitypeListener listener) {
+ intellitypeListeners.add(listener);
+ }
+
+ /**
+ * Cleans up all resources used by JIntellitype.
+ */
+ public void cleanUp() {
+ try {
+ terminate();
+ } catch (UnsatisfiedLinkError ex) {
+ throw new JIntellitypeException(ERROR_MESSAGE, ex);
+ } catch (RuntimeException ex) {
+ throw new JIntellitypeException(ex);
+ }
+ }
+
+ /**
+ * Registers a Hotkey with windows. This combination will be responded to by
+ * all registered HotKeyListeners. Uses the JIntellitypeConstants for MOD,
+ * ALT, CTRL, and WINDOWS keys.
+ *
+ * @param identifier a unique identifier for this key combination
+ * @param modifier MOD_SHIFT, MOD_ALT, MOD_CONTROL, MOD_WIN from
+ * JIntellitypeConstants, or 0 if no modifier needed
+ * @param keycode the key to respond to in Ascii integer, 65 for A
+ */
+ public void registerHotKey(int identifier, int modifier, int keycode) {
+ try {
+ int modifiers = swingToIntelliType(modifier);
+ if (modifiers == 0) {
+ modifiers = modifier;
+ }
+ regHotKey(identifier, modifier, keycode);
+ } catch (UnsatisfiedLinkError ex) {
+ throw new JIntellitypeException(ERROR_MESSAGE, ex);
+ } catch (RuntimeException ex) {
+ throw new JIntellitypeException(ex);
+ }
+ }
+
+ /**
+ * Registers a Hotkey with windows. This combination will be responded to by
+ * all registered HotKeyListeners. Use the Swing InputEvent constants from
+ * java.awt.InputEvent.
+ *
+ * @param identifier a unique identifier for this key combination
+ * @param modifier InputEvent.SHIFT_MASK, InputEvent.ALT_MASK,
+ * InputEvent.CTRL_MASK, or 0 if no modifier needed
+ * @param keycode the key to respond to in Ascii integer, 65 for A
+ */
+ public void registerSwingHotKey(int identifier, int modifier, int keycode) {
+ try {
+ regHotKey(identifier, swingToIntelliType(modifier), keycode);
+ } catch (UnsatisfiedLinkError ex) {
+ throw new JIntellitypeException(ERROR_MESSAGE, ex);
+ } catch (RuntimeException ex) {
+ throw new JIntellitypeException(ex);
+ }
+ }
+
+ /**
+ * Registers a Hotkey with windows. This combination will be responded to by
+ * all registered HotKeyListeners. Use the identifiers CTRL, SHIFT, ALT
+ * and/or WIN.
+ *
+ * @param identifier a unique identifier for this key combination
+ * @param modifierAndKeyCode String with modifiers separated by + and keycode
+ * (e.g. CTRL+SHIFT+A)
+ * @see #registerHotKey(int, int, int)
+ * @see #registerSwingHotKey(int, int, int)
+ */
+ public void registerHotKey(int identifier, String modifierAndKeyCode) {
+ String[] split = modifierAndKeyCode.split("\\+");
+ int mask = 0;
+ int keycode = 0;
+
+ for (int i = 0; i < split.length; i++) {
+ if ("ALT".equalsIgnoreCase(split[i])) {
+ mask += JIntellitype.MOD_ALT;
+ } else if ("CTRL".equalsIgnoreCase(split[i]) || "CONTROL".equalsIgnoreCase(split[i])) {
+ mask += JIntellitype.MOD_CONTROL;
+ } else if ("SHIFT".equalsIgnoreCase(split[i])) {
+ mask += JIntellitype.MOD_SHIFT;
+ } else if ("WIN".equalsIgnoreCase(split[i])) {
+ mask += JIntellitype.MOD_WIN;
+ } else if (keycodeMap.containsKey(split[i].toLowerCase())) {
+ keycode = keycodeMap.get(split[i].toLowerCase());
+ }
+ }
+ registerHotKey(identifier, mask, keycode);
+ }
+
+ /**
+ * Removes a listener for hotkeys.
+ */
+ public void removeHotKeyListener(HotkeyListener listener) {
+ hotkeyListeners.remove(listener);
+ }
+
+ /**
+ * Removes a listener for intellitype commands.
+ */
+ public void removeIntellitypeListener(IntellitypeListener listener) {
+ intellitypeListeners.remove(listener);
+ }
+
+ /**
+ * Unregisters a previously registered Hotkey identified by its unique
+ * identifier.
+ *
+ * @param identifier the unique identifer of this Hotkey
+ */
+ public void unregisterHotKey(int identifier) {
+ try {
+ unregHotKey(identifier);
+ } catch (UnsatisfiedLinkError ex) {
+ throw new JIntellitypeException(ERROR_MESSAGE, ex);
+ } catch (RuntimeException ex) {
+ throw new JIntellitypeException(ex);
+ }
+ }
+
+ /**
+ * Checks to see if this application is already running.
+ *
+ * @param appTitle the name of the application to check for
+ * @return true if running, false if not running
+ */
+ public static boolean checkInstanceAlreadyRunning(String appTitle) {
+ return getInstance().isRunning(appTitle);
+ }
+
+ /**
+ * Checks to make sure the OS is a Windows flavor and that the JIntellitype
+ * DLL is found in the path and the JDK is 32 bit not 64 bit. The DLL
+ * currently only supports 32 bit JDK.
+ *
+ * @return true if Jintellitype may be used, false if not
+ */
+ public static boolean isJIntellitypeSupported() {
+ boolean result = false;
+ String os = "none";
+
+ try {
+ os = System.getProperty("os.name").toLowerCase();
+ } catch (SecurityException ex) {
+ // we are not allowed to look at this property
+ System.err.println("Caught a SecurityException reading the system property "
+ + "'os.name'; the SystemUtils property value will default to null.");
+ }
+
+ // only works on Windows OS currently
+ if (os.startsWith("windows")) {
+ // try an get the instance and if it succeeds then return true
+ try {
+ getInstance();
+ result = true;
+ } catch (Exception e) {
+ result = false;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Gets the libraryLocation.
+ *
+ * @return Returns the libraryLocation.
+ */
+ public static String getLibraryLocation() {
+ return libraryLocation;
+ }
+
+ /**
+ * Sets the libraryLocation.
+ *
+ * @param libraryLocation The libraryLocation to set.
+ */
+ public static void setLibraryLocation(String libraryLocation) {
+ final File dll = new File(libraryLocation);
+ if (!dll.isAbsolute()) {
+ JIntellitype.libraryLocation = dll.getAbsolutePath();
+ } else {
+ // absolute path, no further calculation needed
+ JIntellitype.libraryLocation = libraryLocation;
+ }
+ }
+
+ /**
+ * Notifies all listeners that Hotkey was pressed.
+ *
+ * @param identifier the unique identifier received
+ */
+ protected void onHotKey(final int identifier) {
+ for (final HotkeyListener hotkeyListener : hotkeyListeners) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ hotkeyListener.onHotKey(identifier);
+ }
+ });
+ }
+ }
+
+ /**
+ * Notifies all listeners that Intellitype command was received.
+ *
+ * @param command the unique WM_APPCOMMAND received
+ */
+ protected void onIntellitype(final int command) {
+ for (final IntellitypeListener intellitypeListener : intellitypeListeners) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ intellitypeListener.onIntellitype(command);
+ }
+ });
+ }
+ }
+
+ /**
+ * Swing modifier value to Jintellipad conversion. If no conversion needed
+ * just return the original value. This lets users pass either the original
+ * JIntellitype constants or Swing InputEvent constants.
+ *
+ * @param swingKeystrokeModifier the Swing KeystrokeModifier to check
+ * @return Jintellitype the JIntellitype modifier value
+ */
+ protected static int swingToIntelliType(int swingKeystrokeModifier) {
+ int mask = 0;
+ if ((swingKeystrokeModifier & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) {
+ mask += JIntellitype.MOD_SHIFT;
+ }
+ if ((swingKeystrokeModifier & InputEvent.ALT_MASK) == InputEvent.ALT_MASK) {
+ mask += JIntellitype.MOD_ALT;
+ }
+ if ((swingKeystrokeModifier & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK) {
+ mask += JIntellitype.MOD_CONTROL;
+ }
+ if ((swingKeystrokeModifier & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
+ mask += JIntellitype.MOD_SHIFT;
+ }
+ if ((swingKeystrokeModifier & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK) {
+ mask += JIntellitype.MOD_ALT;
+ }
+ if ((swingKeystrokeModifier & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
+ mask += JIntellitype.MOD_CONTROL;
+ }
+ return mask;
+ }
+
+ /**
+ * Puts all constants from {@link java.awt.event.KeyEvent} in a keycodeMap.
+ * The key is the lower case form of it.
+ * @return Map containing key->keycode mapping DOCU Now enables the user to
+ * use all keys specified here instead of just [A-Z],[0-9] as before
+ */
+ private HashMap
+ * @param appName = the title of the hidden window to search for
+ */
+ private synchronized native boolean isRunning(String appName);
+}
\ No newline at end of file
diff --git a/src/main/java/com/melloware/jintellitype/JIntellitypeConstants.java b/src/main/java/com/melloware/jintellitype/JIntellitypeConstants.java
new file mode 100644
index 0000000..d2bb3f6
--- /dev/null
+++ b/src/main/java/com/melloware/jintellitype/JIntellitypeConstants.java
@@ -0,0 +1,182 @@
+/**
+ * JIntellitype
+ * -----------------
+ * Copyright 2005-2008 Emil A. Lefkof III, Melloware Inc.
+ *
+ * I always give it my best shot to make a program useful and solid, but
+ * remeber that there is absolutely no warranty for using this program as
+ * stated in the following terms:
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.melloware.jintellitype;
+
+/**
+ * Constants from the Windows API used in JIntellitype.
+ *
+ * Message information can be found on MSDN here:
+ * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_appcommand.asp
+ *
+ * Copyright (c) 1999-2008
+ * Melloware, Inc.
+ * Copyright (c) 1999-2008
+ * Melloware, Inc.
+ * Copyright (c) 1999-2008
+ * Melloware, Inc.
+ * @return the full version number of this application
+ */
+ private static String getProjectVersion() {
+ String version;
+
+ try {
+ final Properties pomProperties = new Properties();
+ pomProperties.load(Main.class.getResourceAsStream("/META-INF/maven/com.melloware/jintellitype/pom.properties"));
+ version = pomProperties.getProperty("version");
+ } catch (Exception e) {
+ version = "RUNNING.IN.IDE.FULL";
+ }
+ return version;
+ }
+}
\ No newline at end of file
diff --git a/src/site/fml/faq.fml b/src/site/fml/faq.fml
new file mode 100644
index 0000000..f141139
--- /dev/null
+++ b/src/site/fml/faq.fml
@@ -0,0 +1,131 @@
+
+
+
+ The preferred way of getting in touch with one of the developers of
+ JIntellitype is via the forums.
+ Please direct any matters of general user support, questions, suggestions, discussions, etc.,
+ to the forums.
+
+ In special cases, you may try to contact directly one of the
+ developers or contributors. You
+ can always send request to info@melloware.com also.
+
+ Jintellitype uses the Bloodshed Dev C++ IDE for compiling the JIntellitype.dll.
+
+ 1. Once you have DevC++ installed, just open the JIntellitype.dev project file.
+
+ 2. Navigate to the menu option Project->Options.
+
+ 3. Make sure to set the entries in the screenshot below to your JDK location.
+
+ 4. Change your Project->Options Build Options to point to an output directory of your choosing.
+
+
+ 5. Use the menu or toolbar button to build the DLL!
+
+ JIntellitype is a Java API for interacting with Microsoft Intellitype
+ commands as well as registering for Global Hotkeys in your Java application.
+ The API is a Java JNI library that uses a C++ DLL to do all the communication
+ with Windows. NOTE: This library ONLY works on Windows. If
+ you are looking for a Linux version please see JxGrabKey project on Sourceforge.
+
+ Have you ever wanted to have CTRL+SHIFT+G maximize your Swing application
+ on the desktop? Even if that application did not have focus? Well, now you can! By
+ registering a Windows Hotkey combination, your application will be alerted
+ when the combination you select is pressed anywhere in Windows. Windows has the
+ API call RegisterHotKey
+ for registering a global hotkey combination so that your app receives that message
+ no matter what else you are doing or even if your application has focus. This is
+ a commonly requested feature in Java that has now been implemented by JIntellitype.
+
+ Check out the Quick Start Guide for an example on how to use JIntellitype.
+
+ Have you ever wanted your Java application to react to those special Play, Pause,
+ Stop keys on some newer keyboards like Winamp and Windows Media Player do? Ever wonder how they do it?
+ If you want your application to "listen" for those special keys, now you can with JIntellitype!
+ Just register an IntellitypeListener and you will be notified when those messages are received.
+ To read more about these special commands see the MSDN Documentation
+ about the Intellitype commands.
+
+ Check out the Quick Start Guide for an example on how to use JIntellitype.
+
+ Although JIntellitype is open source, small financial donations are appreciated. By supporting Melloware, you help fund the development
+ (mainly development tools and internet access etc) of Melloware's Software. To send money, simply click on the PayPal icon to the left.
+
+ Jukes cross platform music player and organizer.
+
+ JaJuk cross platform swiss army knife music player including DJ mode and much more!
+
+ C2TN C2TN is the first RSS Reader which integrates completely into your desktop.
+
+ aTunes aTunes is a GPL audio player and manager.
+
+ Topkeys emulates the mouse using the keyboard.
+
+ MiniGen is a program that can generate text in any Windows-based (tested on XP/Vista) application based on the currently selected text in a non-invasive manner.
+
+ Xtreme Media Player is a free cross-platform media player.
+
+ MyTime is a simple time tracker, mostly controlled through the tray icon.
+
+ RadiS is a cool-looking mouse menu that opens upon a global hot-key. Allows sub-menus which will be displayed in an adjacent partly circle.
+
+ JShot is a free and multiplatform screen capture and uploader utility which allows you to capture a part of your screen and publish it in one step.
+
+ OpenSoundboard plays sound files (currently only .wav) when the user presses hotkeys.
+
+ Clipcomrade - simple and free open source windows clipboard manager tool
+
+ Wordoholic Learner - a cross-platform language learning tool
+
+ Here is a simple quick start for getting up and running with JIntellitype quickly.
+ An Example is also included in the
+ distribution to show you how easy it is to use JIntellitype.
+
+ If you are familiar with Eclipse there is a full working example Eclipse project that can be
+ found here Eclipse Example.
+ In Eclipse just navigate to File->Import->Existing Project Into Workspace and you are ready to go.
+
+ 1. Make sure JIntellitype.dll is in your PATH or in \Windows\System32.
+
+ 2. Initialize a JIntellitype object.
+
+ 3. To listen to hotkey's, you need to register the combinations to listen for.
+
+ 4. Make sure to add a HotKeyListener and implement the interface.
+
+ 5. To use Intellitype commands implement the IntellitypeListener interface.
+
+ 6. Don't forget to call the cleanup method to release the DLL resources.
+
+ * Copyright (c) 2006 Melloware, Inc.
+ * @param args any command line arguments
+ */
+ public static void main(String[] args) {
+ // first check to see if an instance of this application is already
+ // running, use the name of the window title of this JFrame for checking
+ if (JIntellitype.checkInstanceAlreadyRunning("JIntellitype Test Application")) {
+ System.exit(1);
+ }
+
+ // next check to make sure JIntellitype DLL can be found and we are on
+ // a Windows operating System
+ if (!JIntellitype.isJIntellitypeSupported()) {
+ System.exit(1);
+ }
+
+ mainFrame = new JIntellitypeTester();
+ mainFrame.setTitle("JIntellitype Test Application");
+ center(mainFrame);
+ mainFrame.setVisible(true);
+ mainFrame.initJIntellitype();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.melloware.jintellitype.HotkeyListener#onHotKey(int)
+ */
+ public void onHotKey(int aIdentifier) {
+ output("WM_HOTKEY message received " + Integer.toString(aIdentifier));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.melloware.jintellitype.IntellitypeListener#onIntellitype(int)
+ */
+ public void onIntellitype(int aCommand) {
+
+ switch (aCommand) {
+ case JIntellitype.APPCOMMAND_BROWSER_BACKWARD:
+ output("BROWSER_BACKWARD message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_BROWSER_FAVOURITES:
+ output("BROWSER_FAVOURITES message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_BROWSER_FORWARD:
+ output("BROWSER_FORWARD message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_BROWSER_HOME:
+ output("BROWSER_HOME message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_BROWSER_REFRESH:
+ output("BROWSER_REFRESH message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_BROWSER_SEARCH:
+ output("BROWSER_SEARCH message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_BROWSER_STOP:
+ output("BROWSER_STOP message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_LAUNCH_APP1:
+ output("LAUNCH_APP1 message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_LAUNCH_APP2:
+ output("LAUNCH_APP2 message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_LAUNCH_MAIL:
+ output("LAUNCH_MAIL message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_MEDIA_NEXTTRACK:
+ output("MEDIA_NEXTTRACK message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_MEDIA_PLAY_PAUSE:
+ output("MEDIA_PLAY_PAUSE message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_MEDIA_PREVIOUSTRACK:
+ output("MEDIA_PREVIOUSTRACK message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_MEDIA_STOP:
+ output("MEDIA_STOP message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_VOLUME_DOWN:
+ output("VOLUME_DOWN message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_VOLUME_UP:
+ output("VOLUME_UP message received " + Integer.toString(aCommand));
+ break;
+ case JIntellitype.APPCOMMAND_VOLUME_MUTE:
+ output("VOLUME_MUTE message received " + Integer.toString(aCommand));
+ break;
+ default:
+ output("Undefined INTELLITYPE message caught " + Integer.toString(aCommand));
+ break;
+ }
+ }
+
+ /**
+ * Centers window on desktop.
+ *
+ * @param aFrame the Frame to center
+ */
+ private static void center(JFrame aFrame) {
+ final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ final Point centerPoint = ge.getCenterPoint();
+ final Rectangle bounds = ge.getMaximumWindowBounds();
+ final int w = Math.min(aFrame.getWidth(), bounds.width);
+ final int h = Math.min(aFrame.getHeight(), bounds.height);
+ final int x = centerPoint.x - (w / 2);
+ final int y = centerPoint.y - (h / 2);
+ aFrame.setBounds(x, y, w, h);
+ if ((w == bounds.width) && (h == bounds.height)) {
+ aFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
+ }
+ aFrame.validate();
+ }
+
+ /**
+ * Method to register a hotkey using the RegisterHotKey Windows API call.
+ *
+ * @param aEvent the ActionEvent fired.
+ */
+ private void btnRegisterHotKey_actionPerformed(ActionEvent aEvent) {
+ // assign the WINDOWS+A key to the unique id 88 for identification
+ JIntellitype.getInstance().registerHotKey(WINDOWS_A, JIntellitype.MOD_WIN, (int) 'A');
+ JIntellitype.getInstance().registerHotKey(ALT_SHIFT_B, JIntellitype.MOD_ALT + JIntellitype.MOD_SHIFT, (int) 'B');
+ JIntellitype.getInstance().registerSwingHotKey(CTRL_SHIFT_C, Event.CTRL_MASK + Event.SHIFT_MASK, (int) 'C');
+
+ // use a 0 for the modifier if you just want a single keystroke to be a hotkey
+ JIntellitype.getInstance().registerHotKey(PRINT_SCREEN, 0, 44);
+ JIntellitype.getInstance().registerHotKey(F9, 0, 120);
+ JIntellitype.getInstance().registerHotKey(F12, JIntellitype.MOD_ALT, 123);
+ JIntellitype.getInstance().registerHotKey(SEMICOLON, 0, 186);
+ // clear the text area
+ textArea.setText("");
+ output("RegisterHotKey WINDOWS+A was assigned uniqueID 88");
+ output("RegisterHotKey ALT+SHIFT+B was assigned uniqueID 89");
+ output("RegisterHotKey CTRL+SHIFT+C was assigned uniqueID 90");
+ output("RegisterHotKey PRINT_SCREEN was assigned uniqueID 91");
+ output("RegisterHotKey F9 was assigned uniqueID 92");
+ output("RegisterHotKey F12 was assigned uniqueID 93");
+ output("RegisterHotKey SEMICOLON was assigned uniqueID 94");
+ output("Press WINDOWS+A or ALT+SHIFT+B or CTRL+SHIFT+C in another application and you will see the debug output in the textarea.");
+ }
+
+ /**
+ * Method to unregister a hotkey using the UnregisterHotKey Windows API call.
+ *
+ * @param aEvent the ActionEvent fired.
+ */
+ private void btnUnregisterHotKey_actionPerformed(ActionEvent aEvent) {
+ JIntellitype.getInstance().unregisterHotKey(WINDOWS_A);
+ JIntellitype.getInstance().unregisterHotKey(ALT_SHIFT_B);
+ JIntellitype.getInstance().unregisterHotKey(CTRL_SHIFT_C);
+ JIntellitype.getInstance().unregisterHotKey(PRINT_SCREEN);
+ JIntellitype.getInstance().unregisterHotKey(F9);
+ JIntellitype.getInstance().unregisterHotKey(F12);
+ JIntellitype.getInstance().unregisterHotKey(SEMICOLON);
+ output("UnregisterHotKey WINDOWS+A");
+ output("UnregisterHotKey ALT+SHIFT+B");
+ output("UnregisterHotKey CTRL+SHIFT+C");
+ output("UnregisterHotKey PRINT_SCREEN");
+ output("UnregisterHotKey F9");
+ output("UnregisterHotKey F12");
+ output("UnregisterHotKey SEMICOLON");
+ output("Press WINDOWS+A or ALT+SHIFT+B in another application and you will NOT see the debug output in the textarea.");
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ */
+ private void initComponents() {
+ mainPanel.setLayout(new BorderLayout());
+ topPanel.setBorder(new EtchedBorder(1));
+ bottomPanel.setLayout(new BorderLayout());
+ bottomPanel.setBorder(new EtchedBorder(1));
+ btnRegisterHotKey.setText("RegisterHotKey");
+ btnRegisterHotKey.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ btnRegisterHotKey_actionPerformed(e);
+ }
+ });
+ btnUnregisterHotKey.setText("UnregisterHotKey");
+ btnUnregisterHotKey.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ btnUnregisterHotKey_actionPerformed(e);
+ }
+ });
+ topPanel.add(btnRegisterHotKey);
+ topPanel.add(btnUnregisterHotKey);
+ scrollPane.getViewport().add(textArea);
+ bottomPanel.add(scrollPane, BorderLayout.CENTER);
+ mainPanel.add(topPanel, BorderLayout.NORTH);
+ mainPanel.add(bottomPanel, BorderLayout.CENTER);
+
+ this.addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosing(java.awt.event.WindowEvent evt) {
+ // don't forget to clean up any resources before close
+ JIntellitype.getInstance().cleanUp();
+ System.exit(0);
+ }
+ });
+
+ this.getContentPane().add(mainPanel);
+ this.pack();
+ this.setSize(800, 600);
+ }
+
+ /**
+ * Initialize the JInitellitype library making sure the DLL is located.
+ *
+ */
+ public void initJIntellitype() {
+ try {
+
+ // initialize JIntellitype with the frame so all windows commands can
+ // be attached to this window
+ JIntellitype.getInstance().addHotKeyListener(this);
+ JIntellitype.getInstance().addIntellitypeListener(this);
+ output("JIntellitype initialized");
+ } catch (RuntimeException ex) {
+ output("Either you are not on Windows, or there is a problem with the JIntellitype library!");
+ }
+ }
+
+ /**
+ * Send the output to the log and the text area.
+ *
+ * @param text the text to output
+ */
+ private void output(String text) {
+ textArea.append(text);
+ textArea.append("\n");
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties
new file mode 100644
index 0000000..f1454f6
--- /dev/null
+++ b/src/test/resources/log4j.properties
@@ -0,0 +1,29 @@
+###################################################################
+# #
+# Copyright 2006 Melloware Inc #
+# #
+# http://www.melloware.com #
+# #
+###################################################################
+
+log4j.rootLogger=DEBUG,stdout
+
+########################################################################
+#
+# Appenders
+#
+########################################################################
+
+
+#### Appender writes to console
+log4j.appender.stdout = org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{MM/dd/yyyy HH:mm:ss} %-5p - [%C{1}.%M:%L] %m %n
+
+#### jukes.log
+log4j.appender.MELLOWARE = org.apache.log4j.FileAppender
+log4j.appender.MELLOWARE.file = ${user.home}/.jintellitype/jintellitype.log
+log4j.appender.MELLOWARE.layout = org.apache.log4j.PatternLayout
+log4j.appender.MELLOWARE.layout.conversionPattern = %d{MM/dd/yyyy HH:mm:ss} %-5p - [%C{1}.%M:%L] %m %n
+log4j.appender.MELLOWARE.append = false
+
+
+
+
+