Pad uit register lezen toegevoegd.
This commit is contained in:
@@ -59,7 +59,7 @@ public class Main extends TaskListener {
|
|||||||
//add(new WMPApplication());
|
//add(new WMPApplication());
|
||||||
add(new GomPlayerApplication());
|
add(new GomPlayerApplication());
|
||||||
//add(new WinampApplication());
|
//add(new WinampApplication());
|
||||||
//add(new iTunesApplication());
|
add(new iTunesApplication());
|
||||||
for (Application application : applicationCycle) {
|
for (Application application : applicationCycle) {
|
||||||
application.start();
|
application.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package pm.application.windows;
|
package pm.application.windows;
|
||||||
|
|
||||||
public enum VirtualKey {
|
public enum Key {
|
||||||
/*
|
/*
|
||||||
* VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
|
* VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
|
||||||
* 0x40 : unassigned
|
* 0x40 : unassigned
|
||||||
@@ -170,7 +170,7 @@ public enum VirtualKey {
|
|||||||
|
|
||||||
protected int code;
|
protected int code;
|
||||||
|
|
||||||
private VirtualKey(int code) {
|
private Key(int code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
18
java/src/pm/application/windows/Type.java
Normal file
18
java/src/pm/application/windows/Type.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package pm.application.windows;
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
UP (0x0101), // WM_KEYUP
|
||||||
|
DOWN (0x0100), // WM_KEYDOWN
|
||||||
|
SYSUP (0x0105), // WM_SYSKEYUP
|
||||||
|
SYSDOWN (0x0104); // WM_SYSKEYDOWN
|
||||||
|
|
||||||
|
protected int code;
|
||||||
|
|
||||||
|
private Type(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,9 +18,7 @@ abstract public class WindowsApplication extends Application {
|
|||||||
protected final static int START_SLEEP = 500;
|
protected final static int START_SLEEP = 500;
|
||||||
|
|
||||||
protected final static int WM_APPCOMMAND = 0x0319;
|
protected final static int WM_APPCOMMAND = 0x0319;
|
||||||
protected final static int WM_KEYDOWN = 0x0100;
|
|
||||||
|
|
||||||
protected String path;
|
|
||||||
protected String program;
|
protected String program;
|
||||||
protected String name;
|
protected String name;
|
||||||
protected String target;
|
protected String target;
|
||||||
@@ -29,6 +27,7 @@ abstract public class WindowsApplication extends Application {
|
|||||||
protected int handle;
|
protected int handle;
|
||||||
protected IntCall sendMessage;
|
protected IntCall sendMessage;
|
||||||
protected IntCall postMessage;
|
protected IntCall postMessage;
|
||||||
|
protected IntCall mapVirtualKey;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@@ -38,11 +37,10 @@ abstract public class WindowsApplication extends Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WindowsApplication(String path, String program, String name) {
|
public WindowsApplication(String program, String name, String target) {
|
||||||
this.path = path;
|
|
||||||
this.program = program;
|
this.program = program;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
target = path + program;
|
this.target = target;
|
||||||
handle = -1;
|
handle = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +69,7 @@ abstract public class WindowsApplication extends Application {
|
|||||||
}
|
}
|
||||||
sendMessage = new IntCall("user32", "SendMessageA");
|
sendMessage = new IntCall("user32", "SendMessageA");
|
||||||
postMessage = new IntCall("user32", "PostMessageA");
|
postMessage = new IntCall("user32", "PostMessageA");
|
||||||
|
mapVirtualKey = new IntCall("user32", "MapVirtualKeyA");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() throws ApplicationExitException {
|
public void exit() throws ApplicationExitException {
|
||||||
@@ -88,19 +87,20 @@ abstract public class WindowsApplication extends Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void key(int key) throws SendKeyException {
|
protected void key(Type key, int code) throws SendKeyException {
|
||||||
|
int scanCode = mapVirtualKey.executeCall(new Object[] {code, 0});
|
||||||
int result = postMessage.executeCall(new Object[] {
|
int result = postMessage.executeCall(new Object[] {
|
||||||
handle, WM_KEYDOWN, key});
|
handle, key.getCode(), code, (scanCode << 16)});
|
||||||
if (result < 1 || postMessage.getLastError() != null) {
|
if (result < 1 || postMessage.getLastError() != null) {
|
||||||
throw new SendKeyException();
|
throw new SendKeyException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void key(char key) throws SendKeyException {
|
protected void key(Type key, char character) throws SendKeyException {
|
||||||
key((int) Character.toUpperCase(key));
|
key(key, (int) Character.toUpperCase(character));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void key(VirtualKey virtualKey) throws SendKeyException {
|
protected void key(Type key, Key virtualKey) throws SendKeyException {
|
||||||
key(virtualKey.getCode());
|
key(key, virtualKey.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,23 @@
|
|||||||
package pm.application.windows.gomplayer;
|
package pm.application.windows.gomplayer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import pm.Action;
|
import pm.Action;
|
||||||
import pm.application.windows.Command;
|
import pm.application.windows.Command;
|
||||||
import pm.application.windows.VirtualKey;
|
import pm.application.windows.Type;
|
||||||
|
import pm.application.windows.Key;
|
||||||
import pm.application.windows.WindowsApplication;
|
import pm.application.windows.WindowsApplication;
|
||||||
import pm.exception.application.ApplicationInitialiseException;
|
|
||||||
import pm.exception.application.windows.SendCommandException;
|
import pm.exception.application.windows.SendCommandException;
|
||||||
import pm.exception.application.windows.SendKeyException;
|
import pm.exception.application.windows.SendKeyException;
|
||||||
|
import pm.util.Native;
|
||||||
|
|
||||||
public class GomPlayerApplication extends WindowsApplication {
|
public class GomPlayerApplication extends WindowsApplication {
|
||||||
protected final static String PATH = "C:\\Program Files (x86)\\GRETECH\\GomPlayer\\";
|
protected final static String REGISTRY = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Clients\\Media\\GomPlayer\\shell\\open\\command";
|
||||||
protected final static String PROGRAM = "GOM.exe";
|
protected final static String PROGRAM = "GOM.exe";
|
||||||
protected final static String NAME = "GOM Player";
|
protected final static String NAME = "GOM Player";
|
||||||
|
|
||||||
protected boolean playing;
|
|
||||||
|
|
||||||
public GomPlayerApplication() {
|
public GomPlayerApplication() {
|
||||||
super(PATH, PROGRAM, NAME);
|
super(PROGRAM, NAME, Native.getValue(REGISTRY));
|
||||||
playing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise() {
|
|
||||||
try {
|
|
||||||
super.initialise();
|
|
||||||
} catch (ApplicationInitialiseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void action(Action action) {
|
public void action(Action action) {
|
||||||
@@ -34,7 +26,7 @@ public class GomPlayerApplication extends WindowsApplication {
|
|||||||
try {
|
try {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case PLAY:
|
case PLAY:
|
||||||
key(VirtualKey.SPACE);
|
key(Type.DOWN, Key.SPACE);
|
||||||
break;
|
break;
|
||||||
case NEXT:
|
case NEXT:
|
||||||
command(Command.MEDIA_NEXTTRACK);
|
command(Command.MEDIA_NEXTTRACK);
|
||||||
@@ -49,13 +41,13 @@ public class GomPlayerApplication extends WindowsApplication {
|
|||||||
command(Command.MEDIA_REWIND);
|
command(Command.MEDIA_REWIND);
|
||||||
break;
|
break;
|
||||||
case MUTE:
|
case MUTE:
|
||||||
key('m');
|
key(Type.DOWN, 'm');
|
||||||
break;
|
break;
|
||||||
case VOLUME_UP:
|
case VOLUME_UP:
|
||||||
key(VirtualKey.UP);
|
key(Type.DOWN, Key.UP);
|
||||||
break;
|
break;
|
||||||
case VOLUME_DOWN:
|
case VOLUME_DOWN:
|
||||||
key(VirtualKey.DOWN);
|
key(Type.DOWN, Key.DOWN);
|
||||||
break;
|
break;
|
||||||
case SHUFFLE:
|
case SHUFFLE:
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package pm.util;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Native {
|
public class Native {
|
||||||
@@ -10,16 +12,54 @@ public class Native {
|
|||||||
File file = new File("native/list.exe");
|
File file = new File("native/list.exe");
|
||||||
Process process = Runtime.getRuntime().exec(file.getPath());
|
Process process = Runtime.getRuntime().exec(file.getPath());
|
||||||
Scanner scanner = new Scanner(process.getInputStream());
|
Scanner scanner = new Scanner(process.getInputStream());
|
||||||
|
ArrayList<Integer> handleList = new ArrayList<Integer>();
|
||||||
|
ArrayList<String> titleList = new ArrayList<String>();
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
try {
|
try {
|
||||||
int handle = new Integer(scanner.nextLine());
|
int handle = new Integer(scanner.nextLine());
|
||||||
String title = scanner.nextLine();
|
String title = scanner.nextLine();
|
||||||
if (title.contains(name)) {
|
if (title.contains(name)) {
|
||||||
System.out.println("Window (" + handle + "): \"" + title + "\"");
|
handleList.add(handle);
|
||||||
return handle;
|
titleList.add(title);
|
||||||
}
|
}
|
||||||
} catch (InputMismatchException e) {}
|
} catch (InputMismatchException e) {}
|
||||||
}
|
}
|
||||||
return -1;
|
int count = handleList.size();
|
||||||
|
if (count == 1) {
|
||||||
|
return handleList.get(0);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
if (titleList.get(i).endsWith(name)) {
|
||||||
|
return handleList.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count > 0 ? handleList.get(0) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValue(String key, String name) throws IOException {
|
||||||
|
Process process = Runtime.getRuntime().exec("reg query " + key);
|
||||||
|
Scanner processScanner = new Scanner(process.getInputStream());
|
||||||
|
try {
|
||||||
|
processScanner.nextLine();
|
||||||
|
processScanner.nextLine();
|
||||||
|
while (processScanner.hasNextLine()) {
|
||||||
|
String line = processScanner.nextLine();
|
||||||
|
int index = line.indexOf(name);
|
||||||
|
if (index > -1) {
|
||||||
|
int begin = index + name.length() + 1;
|
||||||
|
Scanner lineScanner = new Scanner(line.substring(begin));
|
||||||
|
lineScanner.next();
|
||||||
|
return lineScanner.nextLine().trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NoSuchElementException e) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getValue(String key) {
|
||||||
|
try {
|
||||||
|
return getValue(key, "(Default");
|
||||||
|
} catch (IOException e) {}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user