diff --git a/java/src/pm/Main.java b/java/src/pm/Main.java index 6231251..aef9b37 100644 --- a/java/src/pm/Main.java +++ b/java/src/pm/Main.java @@ -40,13 +40,13 @@ public class Main extends TaskListener { } public void initialise() throws DeviceInitialiseException { - //add(new JIntellitypeDevice()); + add(new JIntellitypeDevice()); //add(new PlayerDevice()); //add(new RumblepadDevice()); //add(new WiimoteDevice()); //add(new GUIDevice()); //add(new TextDevice()); - add(new LanTextDevice()); + //add(new LanTextDevice()); for (Device device : deviceList) { try { device.initialise(); @@ -57,7 +57,7 @@ public class Main extends TaskListener { add(new ExampleApplication()); //add(new WMPApplication()); - //add(new GomPlayerApplication()); + add(new GomPlayerApplication()); //add(new WinampApplication()); //add(new iTunesApplication()); for (Application application : applicationCycle) { @@ -95,6 +95,7 @@ public class Main extends TaskListener { break; case PREVIOUS: applicationCycle.previous(); + System.out.println(applicationCycle.current()); break; case EXIT: exit(); diff --git a/java/src/pm/application/windows/WindowsApplication.java b/java/src/pm/application/windows/WindowsApplication.java index 54f9bad..4af787b 100644 --- a/java/src/pm/application/windows/WindowsApplication.java +++ b/java/src/pm/application/windows/WindowsApplication.java @@ -17,6 +17,7 @@ abstract public class WindowsApplication extends Application { protected final static int TERMINATE_SLEEP = 500; protected final static int START_SLEEP = 500; + protected final static int WM_COMMAND = 0x0111; protected final static int WM_APPCOMMAND = 0x0319; protected String program; @@ -25,6 +26,7 @@ abstract public class WindowsApplication extends Application { protected Process process; protected int handle; + protected IntCall sendMessage; protected IntCall postMessage; protected IntCall mapVirtualKey; @@ -87,10 +89,18 @@ abstract public class WindowsApplication extends Application { } } + protected void command(int command) throws SendCommandException { + int result = sendMessage.executeCall(new Object[] { + handle, WM_COMMAND, command}); + if (result < 1 || sendMessage.getLastError() != null) { + throw new SendCommandException(); + } + } + protected void key(Type key, int code) throws SendKeyException { int scanCode = mapVirtualKey.executeCall(new Object[] {code, 0}); int result = postMessage.executeCall(new Object[] { - handle, key.getCode(), code, scanCode << 16}); + handle, key.getCode(), code, 1 | (scanCode << 16)}); if (result < 1 || postMessage.getLastError() != null) { throw new SendKeyException(); } diff --git a/java/src/pm/application/windows/gomplayer/GomPlayerApplication.java b/java/src/pm/application/windows/gomplayer/GomPlayerApplication.java index b425f00..c64a2d1 100644 --- a/java/src/pm/application/windows/gomplayer/GomPlayerApplication.java +++ b/java/src/pm/application/windows/gomplayer/GomPlayerApplication.java @@ -14,7 +14,7 @@ public class GomPlayerApplication extends WindowsApplication { protected final static String NAME = "GOM Player"; public GomPlayerApplication() { - super(PROGRAM, NAME, "C:\\Program Files (x86)\\GomPlayer\\GOM.exe"); + super(PROGRAM, NAME, "C:\\Program Files (x86)\\GRETECH\\GomPlayer\\GOM.exe"); } public void action(Action action) { @@ -23,7 +23,8 @@ public class GomPlayerApplication extends WindowsApplication { try { switch (action) { case PLAY: - key(Type.DOWN, Key.SPACE); + System.out.println("spacie " + handle); + command(0x800C); break; case NEXT: command(Command.MEDIA_NEXTTRACK); diff --git a/java/src/pm/device/jintellitype/Hotkey.java b/java/src/pm/device/jintellitype/Hotkey.java index a5635e3..40bf55a 100644 --- a/java/src/pm/device/jintellitype/Hotkey.java +++ b/java/src/pm/device/jintellitype/Hotkey.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import com.melloware.jintellitype.JIntellitype; +import pm.application.windows.Key; import pm.macro.event.Press; public class Hotkey extends Press { @@ -13,23 +14,27 @@ public class Hotkey extends Press { public Hotkey(int modifier, int keycode) { super(null); // Todo: nettere oplossing zoeken / controleren op null int id = hotkeyList.size(); - button = new HotkeyButton(id); + button = new Modifier(id); jit.registerHotKey(id, modifier, keycode); hotkeyList.add(this); } - public Hotkey(int modifier, char key) { - this(modifier, (int) Character.toUpperCase(key)); + public Hotkey(int modifier, char character) { + this(modifier, (int) Character.toUpperCase(character)); } - public Hotkey(char key) { - this(0, (int) Character.toUpperCase(key)); + public Hotkey(char character) { + this(0, (int) Character.toUpperCase(character)); } public Hotkey(int keycode) { this(0, keycode); } + public Hotkey(Key key) { + this(key.getCode()); + } + public static void initialise(ArrayList actionList, JIntellitype jit) { Hotkey.hotkeyList = actionList; Hotkey.jit = jit; diff --git a/java/src/pm/device/jintellitype/JIntellitypeDevice.java b/java/src/pm/device/jintellitype/JIntellitypeDevice.java index 21b27d6..10fe708 100644 --- a/java/src/pm/device/jintellitype/JIntellitypeDevice.java +++ b/java/src/pm/device/jintellitype/JIntellitypeDevice.java @@ -10,6 +10,7 @@ import pm.Action; import pm.Device; import pm.Target; import pm.Task; +import pm.application.windows.Key; import pm.exception.EventException; import pm.exception.device.DeviceInitialiseException; import pm.macro.event.Press; @@ -30,17 +31,23 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell jit.addHotKeyListener(this); jit.addIntellitypeListener(this); add( - new Hotkey(HotkeyButton.CTRL | HotkeyButton.WIN, 'q'), + new Hotkey(Key.PRIOR), + new Task(Action.PREVIOUS, Target.MAIN)); + add( + new Hotkey(Key.NEXT), + new Task(Action.NEXT, Target.MAIN)); + add( + new Hotkey(Modifier.CTRL | Modifier.WIN, 'q'), new Task(Action.PLAY, Target.APPLICATIONS)); add( - new Hotkey(HotkeyButton.CTRL | HotkeyButton.WIN, 'x'), + new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'), new Task(Action.EXIT, Target.MAIN)); add( - new Hotkey(HotkeyButton.CTRL | HotkeyButton.WIN, 't'), + new Hotkey(Modifier.CTRL | Modifier.WIN, 't'), new Task(Action.TEST, Target.MAIN)); add( - new Hotkey(HotkeyButton.CTRL | HotkeyButton.WIN, 'r'), - new Hotkey(HotkeyButton.CTRL | HotkeyButton.WIN, 's'), + new Hotkey(Modifier.CTRL | Modifier.WIN, 'r'), + new Hotkey(Modifier.CTRL | Modifier.WIN, 's'), new Continuous(Action.REPEAT, Target.APPLICATIONS, 500)); } diff --git a/java/src/pm/device/jintellitype/HotkeyButton.java b/java/src/pm/device/jintellitype/Modifier.java similarity index 78% rename from java/src/pm/device/jintellitype/HotkeyButton.java rename to java/src/pm/device/jintellitype/Modifier.java index ca91592..28b71d2 100644 --- a/java/src/pm/device/jintellitype/HotkeyButton.java +++ b/java/src/pm/device/jintellitype/Modifier.java @@ -4,7 +4,7 @@ import com.melloware.jintellitype.JIntellitype; import pm.Button; -public class HotkeyButton implements Button { +public class Modifier implements Button { public static final int ALT = JIntellitype.MOD_ALT, CTRL = JIntellitype.MOD_CONTROL, @@ -13,7 +13,7 @@ public class HotkeyButton implements Button { protected int code; - protected HotkeyButton(int code) { + protected Modifier(int code) { this.code = code; }