Mimis Native functionaliteit overgebracht op JNI.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
java/mimis.dll
Normal file
BIN
java/mimis.dll
Normal file
Binary file not shown.
@@ -16,7 +16,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
protected static final long serialVersionUID = 1L;
|
protected static final long serialVersionUID = 1L;
|
||||||
protected static final int INTERVAL = 500;
|
protected static final int INTERVAL = 1000;
|
||||||
|
|
||||||
protected T[] manageableArray;
|
protected T[] manageableArray;
|
||||||
protected Map<T, ManageButton<T>> buttonMap;
|
protected Map<T, ManageButton<T>> buttonMap;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public abstract class Worker implements Runnable {
|
|||||||
|
|
||||||
protected boolean run = false;
|
protected boolean run = false;
|
||||||
protected boolean active = false;
|
protected boolean active = false;
|
||||||
|
protected int work = 0;
|
||||||
|
|
||||||
public void start(boolean thread) {
|
public void start(boolean thread) {
|
||||||
run = true;
|
run = true;
|
||||||
@@ -42,6 +43,7 @@ public abstract class Worker implements Runnable {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
notifyAll();
|
notifyAll();
|
||||||
}
|
}
|
||||||
|
log.debug(String.format("%s: %d", getClass(), work));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sleep(int time) {
|
protected void sleep(int time) {
|
||||||
@@ -86,6 +88,7 @@ public abstract class Worker implements Runnable {
|
|||||||
public final void run() {
|
public final void run() {
|
||||||
while (run) {
|
while (run) {
|
||||||
if (active()) {
|
if (active()) {
|
||||||
|
++work;
|
||||||
work();
|
work();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ 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.util.VBScript;
|
|
||||||
|
|
||||||
|
|
||||||
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 String REGISTRY = "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths";
|
||||||
@@ -43,11 +41,7 @@ public abstract class CMDApplication extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean active() {
|
public boolean active() {
|
||||||
try {
|
return active = Native.isRunning(program);
|
||||||
return active = VBScript.isRunning(program);
|
|
||||||
} catch (IOException e) {
|
|
||||||
return active = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package mimis.application.cmd.windows;
|
package mimis.application.cmd.windows;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import mimis.application.cmd.CMDApplication;
|
import mimis.application.cmd.CMDApplication;
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.util.VBScript;
|
import mimis.util.Native;
|
||||||
import mimis.util.Windows;
|
|
||||||
import mimis.value.Command;
|
import mimis.value.Command;
|
||||||
import mimis.value.Key;
|
import mimis.value.Key;
|
||||||
import mimis.value.Type;
|
import mimis.value.Type;
|
||||||
@@ -15,61 +12,64 @@ 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;
|
||||||
|
|
||||||
protected String name;
|
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 Process process;
|
protected Process process;
|
||||||
protected int handle;
|
protected int handle;
|
||||||
|
|
||||||
public WindowsApplication(String program, String title, String name) {
|
public WindowsApplication(String program, String title, String window) {
|
||||||
super(program, title);
|
super(program, title);
|
||||||
this.name = name;
|
this.window = window;
|
||||||
handle = -1;
|
handle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
super.activate();
|
super.activate();
|
||||||
handle = Windows.findWindow(name, null);
|
handle = Native.getHandle(window);
|
||||||
if (handle < 1) {
|
if (handle < 1) {
|
||||||
sleep(START_SLEEP);
|
sleep(START_SLEEP);
|
||||||
handle = Windows.findWindow(name, null);
|
handle = Native.getHandle(window);
|
||||||
}
|
}
|
||||||
active = handle > 0;
|
active = handle > 0;
|
||||||
if (handle < 1) {
|
if (!active) {
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean active() {
|
public boolean active() {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
handle = Windows.findWindow(name, null);
|
handle = Native.getHandle(window);
|
||||||
}
|
}
|
||||||
return super.active();
|
return super.active();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
try {
|
if (!Native.terminate(program)) {
|
||||||
VBScript.terminate(program);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e);
|
|
||||||
throw new DeactivateException();
|
throw new DeactivateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void command(Command command) {
|
protected void command(Command command) {
|
||||||
Windows.sendMessage(handle, Windows.WM_APPCOMMAND, handle, command.getCode() << 16);
|
Native.sendMessage(handle, WM_APPCOMMAND, handle, command.getCode() << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void command(int command) {
|
protected void command(int command) {
|
||||||
Windows.sendMessage(handle, Windows.WM_COMMAND, command, 0);
|
Native.sendMessage(handle, WM_COMMAND, command, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int user(int wParam, int lParam) {
|
protected int user(int wParam, int lParam) {
|
||||||
return Windows.sendMessage(handle, Windows.WM_USER, wParam, lParam);
|
return Native.sendMessage(handle, 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 = Windows.mapVirtualKey(code, Windows.MAPVK_VK_TO_VSC);
|
int scanCode = Native.mapVirtualKey(code, MAPVK_VK_TO_VSC);
|
||||||
Windows.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16));
|
Native.postMessage(handle, type.getCode(), code, 1 | (scanCode << 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void key(Type type, char character) {
|
protected void key(Type type, char character) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import mimis.value.Amount;
|
|||||||
public class GomPlayerApplication extends WindowsApplication {
|
public class GomPlayerApplication extends WindowsApplication {
|
||||||
protected final static String PROGRAM = "GOM.exe";
|
protected final static String PROGRAM = "GOM.exe";
|
||||||
protected final static String TITLE = "GOM Player";
|
protected final static String TITLE = "GOM Player";
|
||||||
protected final static String NAME = "GomPlayer1.x";
|
protected final static String WINDOW = "GomPlayer1.x";
|
||||||
|
|
||||||
protected static final int VOLUME_SLEEP = 100;
|
protected static final int VOLUME_SLEEP = 100;
|
||||||
protected static final int SEEK_SLEEP = 100;
|
protected static final int SEEK_SLEEP = 100;
|
||||||
@@ -19,7 +19,7 @@ public class GomPlayerApplication extends WindowsApplication {
|
|||||||
protected SeekWorker seekWorker;
|
protected SeekWorker seekWorker;
|
||||||
|
|
||||||
public GomPlayerApplication() {
|
public GomPlayerApplication() {
|
||||||
super(PROGRAM, TITLE, NAME);
|
super(PROGRAM, TITLE, WINDOW);
|
||||||
volumeWorker = new VolumeWorker();
|
volumeWorker = new VolumeWorker();
|
||||||
seekWorker = new SeekWorker();
|
seekWorker = new SeekWorker();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ import mimis.value.Action;
|
|||||||
public class WinampApplication extends WindowsApplication {
|
public class WinampApplication extends WindowsApplication {
|
||||||
protected final static String PROGRAM = "winamp.exe";
|
protected final static String PROGRAM = "winamp.exe";
|
||||||
protected final static String TITLE = "Winamp";
|
protected final static String TITLE = "Winamp";
|
||||||
protected final static String NAME = "Winamp v1.x";
|
protected final static String WINDOW = "Winamp v1.x";
|
||||||
|
|
||||||
protected final static int STATUS_PLAYING = 1;
|
protected final static int STATUS_PLAYING = 1;
|
||||||
protected final static int STATUS_PAUSED = 3;
|
protected final static int STATUS_PAUSED = 3;
|
||||||
protected final static int STATUS_STOPPED = 0;
|
protected final static int STATUS_STOPPED = 0;
|
||||||
|
|
||||||
protected final static int IPC_ISPLAYING = 104;
|
protected final static int IPC_ISPLAYING = 104;
|
||||||
protected final static int IPC_GETOUTPUTTIME = 105;
|
protected final static int IPC_GETOUTPUTTIME = 105;
|
||||||
protected final static int IPC_SETVOLUME = 122;
|
protected final static int IPC_SETVOLUME = 122;
|
||||||
@@ -40,9 +40,9 @@ public class WinampApplication extends WindowsApplication {
|
|||||||
protected SeekWorker seekWorker;
|
protected SeekWorker seekWorker;
|
||||||
protected double volume;
|
protected double volume;
|
||||||
protected boolean muted;
|
protected boolean muted;
|
||||||
|
|
||||||
public WinampApplication() {
|
public WinampApplication() {
|
||||||
super(PROGRAM, TITLE, NAME);
|
super(PROGRAM, TITLE, WINDOW);
|
||||||
volume = getVolume();
|
volume = getVolume();
|
||||||
muted = volume == 0;
|
muted = volume == 0;
|
||||||
volumeWorker = new VolumeWorker();
|
volumeWorker = new VolumeWorker();
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import mimis.value.Action;
|
|||||||
public class WMPApplication extends WindowsApplication {
|
public class WMPApplication extends WindowsApplication {
|
||||||
protected final static String PROGRAM = "wmplayer.exe";
|
protected final static String PROGRAM = "wmplayer.exe";
|
||||||
protected final static String TITLE = "Windows Media Player";
|
protected final static String TITLE = "Windows Media Player";
|
||||||
protected final static String NAME = "WMPlayerApp";
|
protected final static String WINDOW = "WMPlayerApp";
|
||||||
|
|
||||||
protected static final int VOLUME_SLEEP = 120;
|
protected static final int VOLUME_SLEEP = 120;
|
||||||
|
|
||||||
protected VolumeWorker volumeWorker;
|
protected VolumeWorker volumeWorker;
|
||||||
|
|
||||||
public WMPApplication() {
|
public WMPApplication() {
|
||||||
super(PROGRAM, TITLE, NAME);
|
super(PROGRAM, TITLE, WINDOW);
|
||||||
volumeWorker = new VolumeWorker();
|
volumeWorker = new VolumeWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package mimis.application.itunes;
|
package mimis.application.itunes;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import mimis.Application;
|
import mimis.Application;
|
||||||
import mimis.Worker;
|
import mimis.Worker;
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.util.VBScript;
|
import mimis.util.Native;
|
||||||
import mimis.value.Action;
|
import mimis.value.Action;
|
||||||
|
|
||||||
import com.dt.iTunesController.ITCOMDisabledReason;
|
import com.dt.iTunesController.ITCOMDisabledReason;
|
||||||
@@ -48,16 +46,12 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean active() {
|
public boolean active() {
|
||||||
try {
|
if (!active && !quiting && Native.isRunning(PROGRAM)) {
|
||||||
if (!active && !quiting && VBScript.isRunning(PROGRAM)) {
|
try {
|
||||||
try {
|
activate();
|
||||||
activate();
|
} catch (ActivateException e) {
|
||||||
} catch (ActivateException e) {
|
log.error(e);
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e);
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
iTunes.getMute();
|
iTunes.getMute();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import mimis.value.Action;
|
|||||||
public class MPCApplication extends WindowsApplication {
|
public class MPCApplication extends WindowsApplication {
|
||||||
protected final static String PROGRAM = "mpc-hc.exe";
|
protected final static String PROGRAM = "mpc-hc.exe";
|
||||||
protected final static String TITLE = "Media Player Classic";
|
protected final static String TITLE = "Media Player Classic";
|
||||||
protected final static String NAME = "MediaPlayerClassicW";
|
protected final static String WINDOW = "MediaPlayerClassicW";
|
||||||
|
|
||||||
protected static final int VOLUME_SLEEP = 50;
|
protected static final int VOLUME_SLEEP = 50;
|
||||||
protected static final int SEEK_SLEEP = 50;
|
protected static final int SEEK_SLEEP = 50;
|
||||||
@@ -18,7 +18,7 @@ public class MPCApplication extends WindowsApplication {
|
|||||||
protected SeekWorker seekWorker;
|
protected SeekWorker seekWorker;
|
||||||
|
|
||||||
public MPCApplication() {
|
public MPCApplication() {
|
||||||
super(PROGRAM, TITLE, NAME);
|
super(PROGRAM, TITLE, WINDOW);
|
||||||
volumeWorker = new VolumeWorker();
|
volumeWorker = new VolumeWorker();
|
||||||
seekWorker = new SeekWorker();
|
seekWorker = new SeekWorker();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import mimis.application.cmd.CMDApplication;
|
|||||||
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.util.VBScript;
|
|
||||||
import mimis.value.Action;
|
import mimis.value.Action;
|
||||||
import mimis.value.Amount;
|
import mimis.value.Amount;
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ public class VLCApplication extends CMDApplication {
|
|||||||
volumeWorker = new VolumeWorker();
|
volumeWorker = new VolumeWorker();
|
||||||
seekWorker = new SeekWorker();
|
seekWorker = new SeekWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
@@ -66,11 +65,7 @@ public class VLCApplication extends CMDApplication {
|
|||||||
super.stop();
|
super.stop();
|
||||||
volumeWorker.stop();
|
volumeWorker.stop();
|
||||||
seekWorker.stop();
|
seekWorker.stop();
|
||||||
try {
|
Native.terminate(program);
|
||||||
VBScript.terminate(program);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void begin(Action action) {
|
public void begin(Action action) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package mimis.device.lirc;
|
package mimis.device.lirc;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import mimis.Button;
|
import mimis.Button;
|
||||||
@@ -12,7 +11,7 @@ import mimis.exception.worker.DeactivateException;
|
|||||||
import mimis.sequence.state.Press;
|
import mimis.sequence.state.Press;
|
||||||
import mimis.sequence.state.Release;
|
import mimis.sequence.state.Release;
|
||||||
import mimis.util.Multiplexer;
|
import mimis.util.Multiplexer;
|
||||||
import mimis.util.VBScript;
|
import mimis.util.Native;
|
||||||
import mimis.util.multiplexer.SignalListener;
|
import mimis.util.multiplexer.SignalListener;
|
||||||
import mimis.value.Signal;
|
import mimis.value.Signal;
|
||||||
|
|
||||||
@@ -56,16 +55,12 @@ public class LircDevice extends Device implements LircButtonListener, SignalList
|
|||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
} else if (!active) {
|
} else if (!active) {
|
||||||
try {
|
if (Native.isRunning(PROGRAM)) {
|
||||||
if (VBScript.isRunning(PROGRAM)) {
|
try {
|
||||||
try {
|
activate();
|
||||||
activate();
|
} catch (ActivateException e) {
|
||||||
} catch (ActivateException e) {
|
log.error(e);
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return active;
|
return active;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
public WiimoteDevice() {
|
public WiimoteDevice() {
|
||||||
super(TITLE);
|
super(TITLE);
|
||||||
eventMapCycle = new WiimoteEventMapCycle();
|
eventMapCycle = new WiimoteEventMapCycle();
|
||||||
//wiimoteDiscovery = new WiimoteDiscovery(this);
|
wiimoteDiscovery = new WiimoteDiscovery(this);
|
||||||
gestureDevice = new GestureDevice();
|
gestureDevice = new GestureDevice();
|
||||||
gestureDevice.add(this);
|
gestureDevice.add(this);
|
||||||
gestureId = 0;
|
gestureId = 0;
|
||||||
@@ -53,7 +53,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
|
|
||||||
/* Worker */
|
/* Worker */
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
//connect();
|
connect();
|
||||||
try {
|
try {
|
||||||
wiimote = wiimoteService.getDevice(this);
|
wiimote = wiimoteService.getDevice(this);
|
||||||
ledWorker.activate();
|
ledWorker.activate();
|
||||||
@@ -65,15 +65,15 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
super.activate();
|
super.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public boolean active() {
|
public boolean active() {
|
||||||
if (wiimote != null) {
|
if (wiimote != null) {
|
||||||
/*if (!ledWorker.active()) {
|
if (!ledWorker.active()) {
|
||||||
try {
|
try {
|
||||||
ledWorker.activate();
|
ledWorker.activate();
|
||||||
} catch (ActivateException e) {
|
} catch (ActivateException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
}*
|
}
|
||||||
connected = false;
|
connected = false;
|
||||||
wiimote.getStatus();
|
wiimote.getStatus();
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -93,16 +93,16 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return active;
|
return active;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
super.stop();
|
super.stop();
|
||||||
ledWorker.stop();
|
ledWorker.stop();
|
||||||
/*if (wiimote != null) {
|
/*if (wiimote != null) {
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}*/
|
||||||
wiimoteService.exit();*/
|
wiimoteService.exit();
|
||||||
//wiimoteDiscovery.stop();
|
wiimoteDiscovery.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Events */
|
/* Events */
|
||||||
@@ -170,7 +170,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void connected() {
|
public void connected() {
|
||||||
try {
|
try {
|
||||||
wiimote = wiimoteService.getDevice(this);
|
wiimote = wiimoteService.getDevice(this);
|
||||||
try {
|
try {
|
||||||
@@ -181,20 +181,20 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
} catch (DeviceNotFoundException e) {
|
} catch (DeviceNotFoundException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/*public void disconnect() {
|
public void disconnect() {
|
||||||
wiimote.disconnect();
|
wiimote.disconnect();
|
||||||
wiimote = null;
|
wiimote = null;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/*public void disconnected() {
|
public void disconnected() {
|
||||||
try {
|
try {
|
||||||
wiimoteDiscovery.activate();
|
wiimoteDiscovery.activate();
|
||||||
} catch (ActivateException e) {
|
} catch (ActivateException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/* Listeners */
|
/* Listeners */
|
||||||
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
||||||
@@ -222,7 +222,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
System.out.printf("id #%d, prob %.0f%%, valid %b\n", event.getId(), 100 * event.getProbability(), event.isValid());
|
System.out.printf("id #%d, prob %.0f%%, valid %b\n", event.getId(), 100 * event.getProbability(), event.isValid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LedWorker extends Worker {
|
class LedWorker extends Worker {
|
||||||
protected ArrayCycle<Integer> ledCycle;
|
protected ArrayCycle<Integer> ledCycle;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class WiimoteDiscovery extends Worker {
|
|||||||
|
|
||||||
public WiimoteDiscovery(WiimoteDevice wiimoteDevice) {
|
public WiimoteDiscovery(WiimoteDevice wiimoteDevice) {
|
||||||
this.wiimoteDevice = wiimoteDevice;
|
this.wiimoteDevice = wiimoteDevice;
|
||||||
|
disconnect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean connect() {
|
protected boolean connect() {
|
||||||
@@ -53,7 +54,6 @@ public class WiimoteDiscovery extends Worker {
|
|||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
super.activate();
|
super.activate();
|
||||||
disconnect = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
|
|||||||
@@ -1,48 +1,44 @@
|
|||||||
package mimis.util;
|
package mimis.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.InputMismatchException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Native {
|
public class Native {
|
||||||
public static int getHandle(String title) throws IOException {
|
static {
|
||||||
String command = String.format("list.exe w");
|
System.loadLibrary("mimis");
|
||||||
Process process = Runtime.getRuntime().exec(command);
|
|
||||||
Scanner scanner = new Scanner(process.getInputStream());
|
|
||||||
scanner.nextLine();
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
Scanner line = new Scanner(scanner.nextLine());
|
|
||||||
line.useDelimiter("\t");
|
|
||||||
try {
|
|
||||||
int handle = line.nextInt();
|
|
||||||
line.nextInt();
|
|
||||||
if (line.hasNext() && line.next().equals(title)) {
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
} catch (InputMismatchException e) {}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getProgram(int processId) throws IOException {
|
public void start() {
|
||||||
String command = String.format("list.exe p");
|
/*int handle = getHandle("Winamp v1.x");
|
||||||
Process process = Runtime.getRuntime().exec(command);
|
System.out.println(handle);
|
||||||
Scanner scanner = new Scanner(process.getInputStream());
|
sendMessage(handle, WindowsApplication.WM_CLOSE, 0, 0);
|
||||||
scanner.nextLine();
|
/*/
|
||||||
while (scanner.hasNextLine()) {
|
while (true) {//Winamp v1.x
|
||||||
Scanner line = new Scanner(scanner.nextLine());
|
System.out.println(isRunning("winamp.exe"));
|
||||||
line.useDelimiter("\t");
|
//System.out.println(new Native().terminate("winamp.exe"));
|
||||||
|
//System.out.println(new Native().running("wmplayer.exe"));
|
||||||
try {
|
try {
|
||||||
if (line.nextInt() == processId) {
|
Thread.sleep(500);
|
||||||
return line.next();
|
} catch (InterruptedException e) {
|
||||||
}
|
// TODO Auto-generated catch block
|
||||||
} catch (InputMismatchException e) {}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Native().start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public native static int getHandle(String window);
|
||||||
|
public native static int sendMessage(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 native static boolean isRunning(String program);
|
||||||
|
public native static boolean terminate(String program);
|
||||||
|
|
||||||
public static String getValue(String key, String name) {
|
public static String getValue(String key, String name) {
|
||||||
String command = String.format("reg query \"%s\"", key);
|
String command = String.format("reg query \"%s\"", key);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
package mimis.util;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
public class VBScript {
|
|
||||||
public static boolean isRunning(String program) throws IOException {
|
|
||||||
boolean found = false;
|
|
||||||
File file = File.createTempFile("vbsutils", ".vbs");
|
|
||||||
FileWriter fileWriter = new FileWriter(file);
|
|
||||||
fileWriter.write(String.format(
|
|
||||||
"Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
|
|
||||||
+ "Set locator = CreateObject(\"WbemScripting.SWbemLocator\")\n"
|
|
||||||
+ "Set service = locator.ConnectServer()\n"
|
|
||||||
+ "Set processes = service.ExecQuery _\n"
|
|
||||||
+ " (\"select * from Win32_Process where name='%s'\")\n"
|
|
||||||
+ "For Each process in processes\n"
|
|
||||||
+ "wscript.echo process.Name\n"
|
|
||||||
+ "Next\n"
|
|
||||||
+ "Set WSHShell = Nothing\n", program));
|
|
||||||
fileWriter.close();
|
|
||||||
Process process = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
|
|
||||||
InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
|
|
||||||
BufferedReader input = new BufferedReader(inputStreamReader);
|
|
||||||
String line = input.readLine();
|
|
||||||
found = line != null && line.equals(program);
|
|
||||||
input.close();
|
|
||||||
try {
|
|
||||||
process.waitFor();
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
file.delete();
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void terminate(String program) throws IOException {
|
|
||||||
File file = File.createTempFile("vbsutils", ".vbs");
|
|
||||||
file.deleteOnExit();
|
|
||||||
FileWriter fileWriter = new FileWriter(file);
|
|
||||||
fileWriter.write(String.format(
|
|
||||||
"Set WshShell = WScript.CreateObject(\"WScript.Shell\")\n"
|
|
||||||
+ "Set locator = CreateObject(\"WbemScripting.SWbemLocator\")\n"
|
|
||||||
+ "Set service = locator.ConnectServer()\n"
|
|
||||||
+ "Set processes = service.ExecQuery _\n"
|
|
||||||
+ " (\"select * from Win32_Process where name='%s'\")\n"
|
|
||||||
+ "For Each process in processes\n"
|
|
||||||
+ "process.Terminate()\n"
|
|
||||||
+ "Next\n"
|
|
||||||
+ "Set WSHShell = Nothing\n", program));
|
|
||||||
fileWriter.close();
|
|
||||||
Process process = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
|
|
||||||
try {
|
|
||||||
process.waitFor();
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package mimis.util;
|
|
||||||
|
|
||||||
import com.eaio.nativecall.IntCall;
|
|
||||||
import com.eaio.nativecall.NativeCall;
|
|
||||||
|
|
||||||
public class Windows {
|
|
||||||
public static final int WM_COMMAND = 0x0111;
|
|
||||||
public static final int WM_APPCOMMAND = 0x0319;
|
|
||||||
public static final int MAPVK_VK_TO_VSC = 0;
|
|
||||||
public static final int WM_USER = 0x0400;
|
|
||||||
|
|
||||||
protected static IntCall findWindow;
|
|
||||||
protected static IntCall sendMessage;
|
|
||||||
protected static IntCall postMessage;
|
|
||||||
protected static IntCall mapVirtualKey;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
NativeCall.init();
|
|
||||||
findWindow = new IntCall("user32", "FindWindowA");
|
|
||||||
sendMessage = new IntCall("user32", "SendMessageA");
|
|
||||||
postMessage = new IntCall("user32", "PostMessageA");
|
|
||||||
mapVirtualKey = new IntCall("user32", "MapVirtualKeyA");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int findWindow(String className, String windowName) {
|
|
||||||
return findWindow.executeCall(new Object[] {className, windowName});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int postMessage(int handle, int message, int wParam, int lParam) {
|
|
||||||
return postMessage.executeCall(new Object[] {handle, message, wParam, lParam});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int sendMessage(int handle, int message, int wParam, int lParam) {
|
|
||||||
return sendMessage.executeCall(new Object[] {handle, message, wParam, lParam});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int mapVirtualKey(int code, int mapType) {
|
|
||||||
return mapVirtualKey.executeCall(new Object[] {code, 0});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user