Register naar native overgebracht en enum met Windows constanten toegevoegd.
This commit is contained in:
@@ -14,8 +14,6 @@
|
|||||||
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
|
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/>
|
<classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jacob-1.15-M3.jar"/>
|
<classpathentry kind="lib" path="lib/jacob-1.15-M3.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/nativecall-0.4.1.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/nativeloader-200505172341.jar"/>
|
|
||||||
<classpathentry kind="lib" path="lib/jxinput.jar"/>
|
<classpathentry kind="lib" path="lib/jxinput.jar"/>
|
||||||
<classpathentry kind="lib" path="cfg"/>
|
<classpathentry kind="lib" path="cfg"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
|||||||
BIN
java/list.exe
BIN
java/list.exe
Binary file not shown.
BIN
java/mimis.dll
BIN
java/mimis.dll
Binary file not shown.
@@ -1,14 +1,17 @@
|
|||||||
package mimis.application.cmd;
|
package mimis.application.cmd;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import mimis.Application;
|
import mimis.Application;
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.util.Native;
|
import mimis.util.Native;
|
||||||
|
import mimis.value.Registry;
|
||||||
|
|
||||||
public abstract class CMDApplication extends Application {
|
public abstract class CMDApplication extends Application {
|
||||||
protected final static String REGISTRY = "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths";
|
protected final static Registry REGISTRY = Registry.LOCAL_MACHINE;
|
||||||
|
protected final static String KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths";
|
||||||
|
|
||||||
protected String program;
|
protected String program;
|
||||||
protected String title;
|
protected String title;
|
||||||
@@ -20,11 +23,6 @@ public abstract class CMDApplication extends Application {
|
|||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
String key = String.format("%s\\%s", REGISTRY, program);
|
|
||||||
return Native.getValue(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
super.activate();
|
super.activate();
|
||||||
String path = getPath();
|
String path = getPath();
|
||||||
@@ -33,7 +31,7 @@ public abstract class CMDApplication extends Application {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
||||||
command = Native.replaceVariables(command);
|
command = replaceVariables(command);
|
||||||
process = Runtime.getRuntime().exec(command);
|
process = Runtime.getRuntime().exec(command);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
@@ -50,4 +48,18 @@ public abstract class CMDApplication extends Application {
|
|||||||
process.destroy();
|
process.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
String key = String.format("%s\\%s", KEY, program);
|
||||||
|
System.out.println(Native.getValue(REGISTRY, key));
|
||||||
|
return Native.getValue(REGISTRY, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replaceVariables(String string) {
|
||||||
|
Map<String, String> env = System.getenv();
|
||||||
|
for (String key : env.keySet()) {
|
||||||
|
string = string.replace(String.format("%%%s%%", key), env.get(key));
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,12 @@ import mimis.util.Native;
|
|||||||
import mimis.value.Command;
|
import mimis.value.Command;
|
||||||
import mimis.value.Key;
|
import mimis.value.Key;
|
||||||
import mimis.value.Type;
|
import mimis.value.Type;
|
||||||
|
import mimis.value.Windows;
|
||||||
|
|
||||||
public abstract class WindowsApplication extends CMDApplication {
|
public abstract class WindowsApplication extends CMDApplication {
|
||||||
protected final static int TERMINATE_SLEEP = 500;
|
protected final static int TERMINATE_SLEEP = 500;
|
||||||
protected final static int START_SLEEP = 500;
|
protected final static int START_SLEEP = 500;
|
||||||
|
|
||||||
public static final int WM_CLOSE = 0x0010;
|
|
||||||
public static final int WM_COMMAND = 0x0111;
|
|
||||||
public static final int WM_APPCOMMAND = 0x0319;
|
|
||||||
public static final int WM_USER = 0x0400;
|
|
||||||
public static final int MAPVK_VK_TO_VSC = 0;
|
|
||||||
|
|
||||||
protected String window;
|
protected String window;
|
||||||
protected Process process;
|
protected Process process;
|
||||||
protected int handle;
|
protected int handle;
|
||||||
@@ -49,26 +44,28 @@ public abstract class WindowsApplication extends CMDApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
if (!Native.terminate(program)) {
|
close();
|
||||||
throw new DeactivateException();
|
}
|
||||||
}
|
|
||||||
|
protected void close() {
|
||||||
|
Native.sendMessage(handle, Windows.WM_CLOSE, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void command(Command command) {
|
protected void command(Command command) {
|
||||||
Native.sendMessage(handle, WM_APPCOMMAND, handle, command.getCode() << 16);
|
Native.sendMessage(handle, Windows.WM_APPCOMMAND, handle, command.getCode() << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void command(int command) {
|
protected void command(int command) {
|
||||||
Native.sendMessage(handle, WM_COMMAND, command, 0);
|
Native.sendMessage(handle, Windows.WM_COMMAND, command, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int user(int wParam, int lParam) {
|
protected int user(int wParam, int lParam) {
|
||||||
return Native.sendMessage(handle, WM_USER, wParam, lParam);
|
return Native.sendMessage(handle, Windows.WM_USER, wParam, lParam);
|
||||||
//return Windows.sendMessage(handle, Windows.WM_USER + wParam, 0, 0);
|
//return Windows.sendMessage(handle, Windows.WM_USER + wParam, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void key(Type type, int code) {
|
protected void key(Type type, int code) {
|
||||||
int scanCode = Native.mapVirtualKey(code, MAPVK_VK_TO_VSC);
|
int scanCode = Native.mapVirtualKey(code, Windows.MAPVK_VK_TO_VSC);
|
||||||
Native.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16));
|
Native.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,11 @@ import mimis.exception.worker.DeactivateException;
|
|||||||
import mimis.util.Native;
|
import mimis.util.Native;
|
||||||
import mimis.value.Action;
|
import mimis.value.Action;
|
||||||
import mimis.value.Amount;
|
import mimis.value.Amount;
|
||||||
|
import mimis.value.Registry;
|
||||||
|
|
||||||
public class VLCApplication extends CMDApplication {
|
public class VLCApplication extends CMDApplication {
|
||||||
protected final static String REGISTRY = "HKCR\\Applications\\vlc.exe\\shell\\Open\\command";
|
protected final static Registry REGISTRY = Registry.CLASSES_ROOT;
|
||||||
|
protected final static String KEY = "Applications\\vlc.exe\\shell\\Open\\command";
|
||||||
protected final static String PROGRAM = "vlc.exe";
|
protected final static String PROGRAM = "vlc.exe";
|
||||||
protected final static String TITLE = "VLC media player";
|
protected final static String TITLE = "VLC media player";
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ public class VLCApplication extends CMDApplication {
|
|||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
Pattern pattern = Pattern.compile("\"([^\"]+)\"");
|
Pattern pattern = Pattern.compile("\"([^\"]+)\"");
|
||||||
Matcher matcher = pattern.matcher(Native.getValue(REGISTRY));
|
Matcher matcher = pattern.matcher(Native.getValue(REGISTRY, KEY));
|
||||||
return matcher.find() ? matcher.group(1) : null;
|
return matcher.find() ? matcher.group(1) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import mimis.exception.button.UnknownButtonException;
|
|||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.util.Native;
|
import mimis.util.Native;
|
||||||
|
import mimis.value.Registry;
|
||||||
|
|
||||||
public class LircService extends Worker {
|
public class LircService extends Worker {
|
||||||
public static final String IP = "localhost";
|
public static final String IP = "localhost";
|
||||||
@@ -37,7 +38,7 @@ public class LircService extends Worker {
|
|||||||
|
|
||||||
public LircService(HashMap<String, LircButton[]> buttonMap) {
|
public LircService(HashMap<String, LircButton[]> buttonMap) {
|
||||||
this(buttonMap, IP, PORT);
|
this(buttonMap, IP, PORT);
|
||||||
send = Native.getValue("HKCU\\Software\\LIRC", "password");
|
send = Native.getValue(Registry.CURRENT_USER, "Software\\LIRC", "password");
|
||||||
}
|
}
|
||||||
|
|
||||||
public LircService(HashMap<String, LircButton[]> buttonMap, String ip, int port) {
|
public LircService(HashMap<String, LircButton[]> buttonMap, String ip, int port) {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package mimis.util;
|
package mimis.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import mimis.value.Registry;
|
||||||
import java.util.Map;
|
import mimis.value.Windows;
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Native {
|
public class Native {
|
||||||
static {
|
static {
|
||||||
@@ -11,10 +9,10 @@ public class Native {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
/*int handle = getHandle("Winamp v1.x");
|
int handle = getHandle("Winamp v1.x");
|
||||||
System.out.println(handle);
|
System.out.println(handle);
|
||||||
sendMessage(handle, WindowsApplication.WM_CLOSE, 0, 0);
|
sendMessage(handle, Windows.WM_CLOSE, 0, 0);
|
||||||
/*/
|
/*
|
||||||
while (true) {//Winamp v1.x
|
while (true) {//Winamp v1.x
|
||||||
System.out.println(isRunning("winamp.exe"));
|
System.out.println(isRunning("winamp.exe"));
|
||||||
//System.out.println(new Native().terminate("winamp.exe"));
|
//System.out.println(new Native().terminate("winamp.exe"));
|
||||||
@@ -25,7 +23,7 @@ public class Native {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -33,43 +31,37 @@ public class Native {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public native static int getHandle(String window);
|
public native static int getHandle(String window);
|
||||||
|
|
||||||
|
public static int sendMessage(int handle, Windows windows, int wParam, int lParam) {
|
||||||
|
return sendMessage(handle, windows.getCode(), wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
public native static int sendMessage(int handle, int message, int wParam, int lParam);
|
public native static int sendMessage(int handle, int message, int wParam, int lParam);
|
||||||
|
|
||||||
|
public static int postMessage(int handle, Windows windows, int wParam, int lParam) {
|
||||||
|
return postMessage(handle, windows.getCode(), wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
public native static int postMessage(int handle, int message, int wParam, int lParam);
|
public native static int postMessage(int handle, int message, int wParam, int lParam);
|
||||||
public static native int mapVirtualKey(int code, int type);
|
|
||||||
|
public static int mapVirtualKey(int code, Windows windows) {
|
||||||
|
return mapVirtualKey(code, windows.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public native static int mapVirtualKey(int code, int type);
|
||||||
|
|
||||||
public native static boolean isRunning(String program);
|
public native static boolean isRunning(String program);
|
||||||
|
|
||||||
public native static boolean terminate(String program);
|
public native static boolean terminate(String program);
|
||||||
|
|
||||||
public static String getValue(String key, String name) {
|
public static String getValue(Registry registry, String key) {
|
||||||
String command = String.format("reg query \"%s\"", key);
|
return getValue(registry, key, "");
|
||||||
try {
|
|
||||||
Process process = Runtime.getRuntime().exec(command);
|
|
||||||
Scanner processScanner = new Scanner(process.getInputStream());
|
|
||||||
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 (IOException e) {
|
|
||||||
} catch (NoSuchElementException e) {}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getValue(String key) {
|
public static String getValue(Registry registry, String key, String name) {
|
||||||
return getValue(key, "(Default)");
|
return getValue(registry.getCode(), key, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String replaceVariables(String string) {
|
public native static String getValue(int registry, String key, String name);
|
||||||
Map<String, String> env = System.getenv();
|
|
||||||
for (String key : env.keySet()) {
|
|
||||||
string = string.replace(String.format("%%%s%%", key), env.get(key));
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
21
java/src/mimis/value/Registry.java
Normal file
21
java/src/mimis/value/Registry.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package mimis.value;
|
||||||
|
|
||||||
|
public enum Registry {
|
||||||
|
CLASSES_ROOT (0x80000000),
|
||||||
|
CURRENT_USER (0x80000001),
|
||||||
|
LOCAL_MACHINE (0x80000002),
|
||||||
|
USERS (0x80000003),
|
||||||
|
PERFORMANCE_DATA (0x80000004),
|
||||||
|
CURRENT_CONFIG (0x80000005),
|
||||||
|
DYN_DATA (0x80000006);
|
||||||
|
|
||||||
|
protected int code;
|
||||||
|
|
||||||
|
private Registry(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
java/src/mimis/value/Windows.java
Normal file
19
java/src/mimis/value/Windows.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package mimis.value;
|
||||||
|
|
||||||
|
public enum Windows {
|
||||||
|
WM_CLOSE (0x0010),
|
||||||
|
WM_COMMAND (0x0111),
|
||||||
|
WM_APPCOMMAND (0x0319),
|
||||||
|
WM_USER (0x0400),
|
||||||
|
MAPVK_VK_TO_VSC (0);
|
||||||
|
|
||||||
|
protected int code;
|
||||||
|
|
||||||
|
private Windows(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user