Message Hook Window is working, Added BAR sendKeys and fixed colon key.
Message Hook Window is working and will allow you to see all messages being processed by a target window. Had to build Message Hook Window inside the native MsgHook.dll was having issues keep a java window's WndProc callback processing.
This commit is contained in:
@@ -8,14 +8,17 @@
|
||||
package org.synthuse;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Callback;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinDef.*;
|
||||
import com.sun.jna.platform.win32.Advapi32Util;
|
||||
import com.sun.jna.platform.win32.BaseTSD.LONG_PTR;
|
||||
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR;
|
||||
import com.sun.jna.platform.win32.WinDef;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
@@ -24,6 +27,7 @@ import com.sun.jna.platform.win32.WinUser;
|
||||
import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER;
|
||||
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
public class Api {
|
||||
@@ -198,11 +202,48 @@ public class Api {
|
||||
public int cch; //The length of the menu item text, in characters, when information is received about a menu item of the MFT_STRING type.
|
||||
public HBITMAP hbmpItem; //A handle to the bitmap to be displayed, or it can be one of the values in the following table.
|
||||
}
|
||||
|
||||
public static class COPYDATASTRUCT extends Structure {
|
||||
//The by-reference version of this structure.
|
||||
public static class ByReference extends COPYDATASTRUCT implements Structure.ByReference { }
|
||||
|
||||
public COPYDATASTRUCT() { }
|
||||
|
||||
//Instantiates a new COPYDATASTRUCT with existing data given the address of that data.
|
||||
public COPYDATASTRUCT(final long pointer) {
|
||||
this(new Pointer(pointer));
|
||||
}
|
||||
|
||||
//Instantiates a new COPYDATASTRUCT with existing data given a pointer to that data.
|
||||
public COPYDATASTRUCT(final Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public ULONG_PTR dwData; // The data to be passed to the receiving application.
|
||||
public int cbData; //The size, in bytes, of the data pointed to by the lpData
|
||||
public Pointer lpData;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected final List getFieldOrder() {
|
||||
return Arrays.asList(new String[] {"dwData", "cbData", "lpData" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface WNDPROC extends StdCallCallback {
|
||||
|
||||
LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam);
|
||||
|
||||
}
|
||||
|
||||
public interface User32 extends W32APIOptions {
|
||||
User32 instance = (User32) Native.loadLibrary("user32", User32.class, DEFAULT_OPTIONS);
|
||||
|
||||
int SetWindowLongPtr(HWND hWnd, int nIndex, Callback callback);
|
||||
LRESULT CallWindowProc(LONG_PTR proc, HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam);
|
||||
|
||||
boolean ShowWindow(HWND hWnd, int nCmdShow);
|
||||
boolean SetForegroundWindow(HWND hWnd);
|
||||
void SwitchToThisWindow(HWND hWnd, boolean fAltTab);
|
||||
@@ -291,13 +332,16 @@ public class Api {
|
||||
kernel32 = Kernel32.instance;
|
||||
}
|
||||
|
||||
public static String GetHandleAsString(HWND hWnd) {
|
||||
public static Long GetHandleAsLong(HWND hWnd) {
|
||||
if (hWnd == null)
|
||||
return "0";
|
||||
return (long)0;
|
||||
//String longHexStr = hWnd.toString().substring("native@".length());
|
||||
String longHexStr = hWnd.getPointer().toString().substring("native@".length());
|
||||
Long l = Long.decode(longHexStr);
|
||||
return l.toString();
|
||||
return Long.decode(longHexStr);
|
||||
}
|
||||
|
||||
public static String GetHandleAsString(HWND hWnd) {
|
||||
return GetHandleAsLong(hWnd).toString();
|
||||
}
|
||||
|
||||
public static HWND GetHandleFromString(String hWnd) {
|
||||
@@ -583,4 +627,26 @@ public class Api {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static HWND FindMainWindowFromPid(final long targetProcessId) {
|
||||
|
||||
final List<HWND> resultList = new ArrayList<HWND>();
|
||||
class ParentWindowCallback implements WinUser.WNDENUMPROC {
|
||||
@Override
|
||||
public boolean callback(HWND hWnd, Pointer lParam) {
|
||||
PointerByReference pointer = new PointerByReference();
|
||||
User32.instance.GetWindowThreadProcessId(hWnd, pointer);
|
||||
long pid = pointer.getPointer().getInt(0);
|
||||
if (pid == targetProcessId)
|
||||
if (resultList.isEmpty())
|
||||
resultList.add(hWnd);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Api.User32.instance.EnumWindows(new ParentWindowCallback(), 0);
|
||||
if (!resultList.isEmpty())
|
||||
return resultList.get(0);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ public class CommandPopupMenu extends JPopupMenu {
|
||||
CommandMenuItem mntmSetTargetOffset = new CommandMenuItem("setTargetOffset", 3, false);
|
||||
mnMouse.add(mntmSetTargetOffset);
|
||||
|
||||
|
||||
JMenu mnWinMessages = new JMenu("Win Messages");
|
||||
add(mnWinMessages);
|
||||
|
||||
@@ -112,6 +113,9 @@ public class CommandPopupMenu extends JPopupMenu {
|
||||
|
||||
CommandMenuItem mntmSelectContextMenuId = new CommandMenuItem("selectContextMenuId", 3);
|
||||
mnWinMessages.add(mntmSelectContextMenuId);
|
||||
|
||||
CommandMenuItem mntmSendCommandMsg = new CommandMenuItem("sendCommandMsg", 4);
|
||||
mnWinMessages.add(mntmSendCommandMsg);
|
||||
|
||||
CommandMenuItem mntmSetcursorposition = new CommandMenuItem("setCursorPosition", 3);
|
||||
mnWinMessages.add(mntmSetcursorposition);
|
||||
@@ -142,7 +146,7 @@ public class CommandPopupMenu extends JPopupMenu {
|
||||
|
||||
CommandMenuItem mntmGetwindowclass = new CommandMenuItem("getWindowClass", 2);
|
||||
mnWinMessages.add(mntmGetwindowclass);
|
||||
|
||||
|
||||
CommandMenuItem mntmDisplayText = new CommandMenuItem("displayText", 3, false);
|
||||
add(mntmDisplayText);
|
||||
|
||||
@@ -226,6 +230,8 @@ public class CommandPopupMenu extends JPopupMenu {
|
||||
actionStr += "on | " + xpathItem + " | ";
|
||||
if (paramCount > 2)
|
||||
actionStr += "with | |";
|
||||
if (paramCount > 3)
|
||||
actionStr += " and | |";
|
||||
return actionStr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,8 @@ public class CommandProcessor implements Runnable{
|
||||
if (!line.trim().startsWith("|"))
|
||||
continue; //skip if it doesn't start with bar
|
||||
String[] parsed = line.split("\\|");
|
||||
//
|
||||
|
||||
//System.out.println("line: " + line);
|
||||
//System.out.println("parsed len = " + parsed.length);
|
||||
//System.out.println("parsed 2 = " + parsed[2]);
|
||||
@@ -113,6 +115,8 @@ public class CommandProcessor implements Runnable{
|
||||
execute(parsed[2].trim(), new String[] {parsed[4].trim()});
|
||||
if (parsed.length == 7)
|
||||
execute(parsed[2].trim(), new String[] {parsed[4].trim(), parsed[6].trim()});
|
||||
if (parsed.length == 9)
|
||||
execute(parsed[2].trim(), new String[] {parsed[4].trim(), parsed[6].trim(), parsed[8].trim()});
|
||||
|
||||
if (executeErrorCount > 0) //check if any errors occurred
|
||||
++scriptErrorCount;
|
||||
@@ -215,6 +219,8 @@ public class CommandProcessor implements Runnable{
|
||||
return win.cmdSelectMenu(args);
|
||||
if (command.equals("selectContextMenuId"))
|
||||
return win.cmdSelectContextMenuId(args);
|
||||
if (command.equals("sendCommandMsg"))
|
||||
return win.cmdSendCommandMsg(args);
|
||||
if (command.equals("windowMinimize"))
|
||||
return win.cmdWindowMinimize(args);
|
||||
if (command.equals("windowMaximize"))
|
||||
|
||||
@@ -130,7 +130,7 @@ public class DragTarget extends JLabel {
|
||||
|
||||
@Override
|
||||
public boolean importData(TransferSupport support) {
|
||||
System.out.println("importData");
|
||||
//System.out.println("importData");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski7@gmail.com
|
||||
*/
|
||||
|
||||
// This class is not actually used and is only here as a reference
|
||||
|
||||
package org.synthuse;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
@@ -6,37 +15,57 @@ import java.awt.BorderLayout;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
import com.sun.jna.platform.win32.WinDef.*;
|
||||
import com.sun.jna.platform.win32.Kernel32;
|
||||
import com.sun.jna.platform.win32.WinUser.HHOOK;
|
||||
import com.sun.jna.platform.win32.WinUser.HOOKPROC;
|
||||
import com.sun.jna.platform.win32.WinUser.MSG;
|
||||
import com.sun.jna.platform.win32.BaseTSD.LONG_PTR;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Component;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Box;
|
||||
|
||||
|
||||
public class MessageHookFrame extends JFrame {
|
||||
|
||||
private static final long serialVersionUID = -5863279004595502801L;
|
||||
|
||||
public static final String newLine = System.getProperty("line.separator");
|
||||
|
||||
public static final int WH_CALLWNDPROC = 4;
|
||||
public static final int WH_GETMESSAGE = 3;
|
||||
public static final int WH_KEYBOARD_LL = 13;
|
||||
|
||||
public static final int WM_COPYDATA = 74;
|
||||
public static final int GWLP_WNDPROC = -4;
|
||||
|
||||
private JTextArea textArea;
|
||||
private JButton btnSave;
|
||||
private JButton btnStartMsgHook;
|
||||
private JButton btnPause;
|
||||
private JButton btnClear;
|
||||
private LONG_PTR oldWndProc;
|
||||
private MsgHook msgHook = null;
|
||||
|
||||
public static HHOOK hHook = null;
|
||||
//public static LowLevelKeyboardProc lpfn;
|
||||
public static volatile boolean quit = false;
|
||||
private JLabel lblTargetHwnd;
|
||||
public JTextField txtTarget;
|
||||
private Component horizontalStrut;
|
||||
|
||||
public MessageHookFrame() {
|
||||
setTitle("Message Hook");
|
||||
@@ -60,11 +89,42 @@ public class MessageHookFrame extends JFrame {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
lblTargetHwnd = new JLabel("Target HWND: ");
|
||||
toolBar.add(lblTargetHwnd);
|
||||
|
||||
txtTarget = new JTextField();
|
||||
txtTarget.setMaximumSize(new Dimension(70, 2147483647));
|
||||
txtTarget.setText("0");
|
||||
toolBar.add(txtTarget);
|
||||
txtTarget.setColumns(10);
|
||||
|
||||
horizontalStrut = Box.createHorizontalStrut(20);
|
||||
toolBar.add(horizontalStrut);
|
||||
toolBar.add(btnStartMsgHook);
|
||||
|
||||
btnPause = new JButton("Pause");
|
||||
btnPause.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
final HWND myHwnd = new HWND(Native.getWindowPointer(MessageHookFrame.this));
|
||||
oldWndProc = User32.INSTANCE.GetWindowLongPtr(myHwnd, GWLP_WNDPROC);
|
||||
|
||||
Api.WNDPROC wndProc = new Api.WNDPROC() {
|
||||
public LRESULT callback(HWND hWnd, int uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
if (uMsg == WM_COPYDATA){
|
||||
System.out.println("WM_COPYDATA");
|
||||
//handle the window message here
|
||||
}
|
||||
else
|
||||
System.out.println("MESSAGE: " + uMsg);
|
||||
return Api.User32.instance.CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam);
|
||||
//return new LRESULT(0);
|
||||
//return User32.INSTANCE.DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
};
|
||||
|
||||
Api.User32.instance.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, wndProc);
|
||||
}
|
||||
});
|
||||
toolBar.add(btnPause);
|
||||
@@ -89,62 +149,142 @@ public class MessageHookFrame extends JFrame {
|
||||
|
||||
textArea = new JTextArea();
|
||||
scrollPane.setViewportView(textArea);
|
||||
|
||||
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
//TestIdeFrame.this.setVisible(false);
|
||||
MessageHookFrame.this.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
super.setAlwaysOnTop(SynthuseDlg.config.isAlwaysOnTop());
|
||||
|
||||
}
|
||||
/*
|
||||
typedef struct
|
||||
{
|
||||
HWND hWnd;
|
||||
int nCode;
|
||||
DWORD dwHookType;
|
||||
WPARAM wParam;
|
||||
LPARAM lParam;
|
||||
TCHAR wParamStr[25];
|
||||
TCHAR lParamStr[25];
|
||||
}HEVENT;
|
||||
*/
|
||||
|
||||
public static class HEVENT extends Structure {
|
||||
//The by-reference version of this structure.
|
||||
public static class ByReference extends HEVENT implements Structure.ByReference { }
|
||||
|
||||
public HEVENT() { }
|
||||
|
||||
//Instantiates a new COPYDATASTRUCT with existing data given the address of that data.
|
||||
public HEVENT(final long pointer) {
|
||||
this(new Pointer(pointer));
|
||||
}
|
||||
|
||||
//Instantiates a new COPYDATASTRUCT with existing data given a pointer to that data.
|
||||
public HEVENT(final Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WORD hWnd;
|
||||
public WORD nCode;
|
||||
public DWORD dwHookType;
|
||||
public DWORD wParam;
|
||||
public DWORD lParam;
|
||||
//public TCHAR wParamStr[25];
|
||||
//public TCHAR lParamStr[25];
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected final List getFieldOrder() {
|
||||
return Arrays.asList(new String[] {"hWnd", "nCode", "dwHookType", "wParam", "lParam" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void createMessageHook() {
|
||||
/*
|
||||
// Below set windows hook is called from inside the native DLL
|
||||
if (hHook != null)
|
||||
return; //hook already running don't add anymore
|
||||
System.out.println("starting global message hook");
|
||||
HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
|
||||
int threadId = Kernel32.INSTANCE.GetCurrentThreadId();
|
||||
HOOKPROC lpfn = new HOOKPROC() {
|
||||
@SuppressWarnings("unused")
|
||||
public LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) {
|
||||
//System.out.println("Msg " + nCode);
|
||||
|
||||
return User32.INSTANCE.CallNextHookEx(hHook, nCode, wParam, lParam);
|
||||
}
|
||||
};
|
||||
|
||||
hHook = User32.INSTANCE.SetWindowsHookEx(WH_CALLWNDPROC, lpfn, hMod, threadId);
|
||||
if (hHook == null)
|
||||
return;
|
||||
*/
|
||||
MsgHook mh = new MsgHook();
|
||||
//mh.setMessageHook(hwnd, threadId);
|
||||
quit = false; //don't quit
|
||||
|
||||
MSG msg = new MSG();
|
||||
try {
|
||||
|
||||
while (!quit) {
|
||||
User32.INSTANCE.PeekMessage(msg, null, 0, 0, 1);
|
||||
if (msg.message == WM_COPYDATA){ // && msg.wParam.intValue() == 1
|
||||
System.out.println("WM_COPYDATA");
|
||||
msg = new MSG(); //must clear msg so it doesn't repeat
|
||||
//find the HWND and current WNDPROC on this java window
|
||||
final HWND myHwnd = new HWND(Native.getWindowPointer(MessageHookFrame.this));
|
||||
oldWndProc = User32.INSTANCE.GetWindowLongPtr(myHwnd, GWLP_WNDPROC);
|
||||
|
||||
Api.WNDPROC wndProc = new Api.WNDPROC() {
|
||||
public LRESULT callback(HWND hWnd, int uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
if (uMsg == WM_COPYDATA){
|
||||
//(COPYDATASTRUCT *) lParam
|
||||
//if( pCopyDataStruct->cbData == sizeof(HEVENT)) {
|
||||
// HEVENT Event;
|
||||
// memcpy(&Event, (HEVENT*)pCopyDataStruct->lpData, sizeof(HEVENT)); // transfer data to internal variable
|
||||
//}
|
||||
|
||||
Api.WinDefExt.COPYDATASTRUCT cds = new Api.WinDefExt.COPYDATASTRUCT(lParam.longValue());
|
||||
HEVENT he = new HEVENT(cds.lpData);
|
||||
appendLine("msg: WM_COPYDATA" + cds.cbData);
|
||||
appendLine("hwnd: " + he.hWnd + ", msg: " + he.nCode + ", wParam: " + he.wParam + ", lParam: " + he.lParam);
|
||||
//System.out.println("WM_COPYDATA");
|
||||
//handle the window message here
|
||||
}
|
||||
Thread.sleep(10);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//else
|
||||
// System.out.println("MESSAGE: " + uMsg);
|
||||
|
||||
return Api.User32.instance.CallWindowProc(oldWndProc, hWnd, uMsg, wParam, lParam);
|
||||
//return User32.INSTANCE.DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
};
|
||||
|
||||
//Set the wndproc callback on this MessageHookFrame so we can process Windows Messages
|
||||
Api.User32.instance.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, wndProc);
|
||||
|
||||
IntByReference intByRef = new IntByReference(0);
|
||||
final int threadId = User32.INSTANCE.GetWindowThreadProcessId(Api.GetHandleFromString(txtTarget.getText()), intByRef);
|
||||
|
||||
//int myPid = Kernel32.INSTANCE.GetCurrentProcessId();
|
||||
//HWND myHwnd = Api.FindMainWindowFromPid(myPid);
|
||||
final long myHwndLong = Api.GetHandleAsLong(myHwnd);
|
||||
|
||||
//System.out.println("Starting Msg Hook for " + myHwndLong + " on id " + threadId);
|
||||
if (threadId == 0 ) // don't allow global
|
||||
{
|
||||
System.out.println("Not allowing global message hook " + threadId);
|
||||
User32.INSTANCE.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, oldWndProc); //restore default WNDPROC
|
||||
quit = true;
|
||||
return;
|
||||
}
|
||||
System.out.println("message loop stopped");
|
||||
unhook();
|
||||
|
||||
msgHook = new MsgHook();
|
||||
if (!msgHook.setMessageHook((int) myHwndLong, threadId))
|
||||
appendLine("Error setting message hook");
|
||||
else
|
||||
appendLine("Message hook started");
|
||||
|
||||
}
|
||||
|
||||
public void unhook() {
|
||||
if (hHook == null)
|
||||
return;
|
||||
if (!User32.INSTANCE.UnhookWindowsHookEx(hHook))
|
||||
System.out.println("Failed to unhook");
|
||||
System.out.println("Unhooked");
|
||||
hHook = null;
|
||||
public void unhook(MsgHook msgHook) {
|
||||
msgHook.removeMessageHook();
|
||||
}
|
||||
|
||||
//stops Keyboard hook and causes the unhook command to be called
|
||||
public static void stopMessageHook() {
|
||||
public void stopMessageHook() {
|
||||
//if (!quit) //if not hooked skip
|
||||
// return;
|
||||
quit = true;
|
||||
appendLine("Message hook stopped");
|
||||
final HWND myHwnd = new HWND(Native.getWindowPointer(MessageHookFrame.this));
|
||||
User32.INSTANCE.SetWindowLongPtr(myHwnd, GWLP_WNDPROC, oldWndProc); //restore default WNDPROC
|
||||
unhook(msgHook);
|
||||
}
|
||||
|
||||
public void appendLine(String txt)
|
||||
{
|
||||
textArea.append(txt + newLine);
|
||||
textArea.setCaretPosition(textArea.getDocument().getLength());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski7@gmail.com
|
||||
*/
|
||||
|
||||
package org.synthuse;
|
||||
|
||||
import java.io.File;
|
||||
@@ -7,6 +14,7 @@ import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class MsgHook {
|
||||
@@ -78,7 +86,27 @@ public class MsgHook {
|
||||
System.load(temp.getAbsolutePath());
|
||||
}
|
||||
|
||||
public native boolean setMessageHook(long hwnd, long threadId);
|
||||
//public native boolean initialize(int hwnd);
|
||||
public native boolean createMsgHookWindow();
|
||||
public native boolean setMsgHookWindowTargetHwnd(int hwnd);
|
||||
public native boolean setMsgHookWindowTargetClass(String classname);
|
||||
public native boolean setMessageHook(int hwnd, int threadId);
|
||||
public native boolean removeMessageHook();
|
||||
//public native boolean shutdown();
|
||||
|
||||
public static Thread createMsgHookWinThread(final long targetHwnd)
|
||||
{
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
MsgHook mh = new MsgHook();
|
||||
mh.setMsgHookWindowTargetClass("");
|
||||
if (targetHwnd != 0)
|
||||
mh.setMsgHookWindowTargetHwnd((int)targetHwnd);
|
||||
mh.createMsgHookWindow();
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -428,6 +428,10 @@ ALT %
|
||||
specialKeyFlag = false;
|
||||
pressKeyCodes(robot, new int[]{KeyEvent.VK_CANCEL} );
|
||||
}
|
||||
else if (specialKey.equals("{BAR}")) {
|
||||
specialKeyFlag = false;
|
||||
pressKeyCodes(robot, new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_BACK_SLASH});
|
||||
}
|
||||
else if (specialKey.equals("{{}")) {
|
||||
specialKeyFlag = false;
|
||||
pressKeyCodes(robot, new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_OPEN_BRACKET} );
|
||||
@@ -602,7 +606,7 @@ ALT %
|
||||
case '}': return(new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_CLOSE_BRACKET});
|
||||
case '|': return(new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_BACK_SLASH});
|
||||
case ';': return(new int[]{KeyEvent.VK_SEMICOLON});
|
||||
case ':': return(new int[]{KeyEvent.VK_COLON});
|
||||
case ':': return(new int[]{KeyEvent.VK_SHIFT, KeyEvent.VK_SEMICOLON});
|
||||
case '\'': return(new int[]{KeyEvent.VK_QUOTE});
|
||||
case '"': return(new int[]{KeyEvent.VK_QUOTEDBL});
|
||||
case ',': return(new int[]{KeyEvent.VK_COMMA});
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SynthuseDlg extends JFrame {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String VERSION_STR = "1.2.0";
|
||||
public static String VERSION_STR = "1.2.1";
|
||||
|
||||
public static String RES_STR_MAIN_ICON = "/org/synthuse/img/gnome-robots.png";
|
||||
public static String RES_STR_REFRESH_IMG = "/org/synthuse/img/rapidsvn.png";
|
||||
@@ -83,7 +83,7 @@ public class SynthuseDlg extends JFrame {
|
||||
private JButton btnAdvanced;
|
||||
|
||||
private TestIdeFrame testIde = null;
|
||||
private MessageHookFrame msgHook = null;
|
||||
//private MessageHookFrame msgHook = null;
|
||||
private int targetX;
|
||||
private int targetY;
|
||||
private UiaBridge uiabridge = new UiaBridge();
|
||||
@@ -187,9 +187,19 @@ public class SynthuseDlg extends JFrame {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
//System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed.");
|
||||
if (event.getActionCommand() == "Message Hook"){
|
||||
/*
|
||||
if (msgHook == null)
|
||||
msgHook = new MessageHookFrame();
|
||||
msgHook.setVisible(true);
|
||||
msgHook.txtTarget.setText(lastDragHwnd);
|
||||
*/
|
||||
long lastHwndLong = 0;
|
||||
try {
|
||||
lastHwndLong = Long.parseLong(lastDragHwnd);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
MsgHook.createMsgHookWinThread(lastHwndLong);
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -224,7 +234,9 @@ public class SynthuseDlg extends JFrame {
|
||||
about += " disableUiaBridge - " + config.isUiaBridgeDisabled() + "\n";
|
||||
about += " disableFiltersUia - " + config.isFilterUiaDisabled() + "\n";
|
||||
|
||||
about += "\nSystem information: \n";
|
||||
about += " Synthuse location - " + SynthuseDlg.class.getProtectionDomain().getCodeSource().getLocation().toString();
|
||||
|
||||
about += "\n\nSystem information: \n";
|
||||
about += " Java version - " + System.getProperty("java.version") + "\n";
|
||||
about += " Java home - " + System.getProperty("java.home") + "\n";
|
||||
about += " OS Name - " + System.getProperty("os.name") + "\n";
|
||||
@@ -380,12 +392,17 @@ public class SynthuseDlg extends JFrame {
|
||||
lblStatus.setText(status);
|
||||
}
|
||||
@Override
|
||||
public void executionCompleted(Object input, String results) { //buildXpathStatementThreaded finished, with results being the xpath statement
|
||||
public void executionCompleted(Object input, final String results) { //buildXpathStatementThreaded finished, with results being the xpath statement
|
||||
if (input instanceof HWND) { // in case thread takes long time to process
|
||||
lastDragHwnd = Api.GetHandleAsString((HWND)input);
|
||||
}
|
||||
XpathManager.nextXpathMatch(results, textPane, lblStatus, true);
|
||||
cmbXpath.setSelectedItem(results);
|
||||
SwingUtilities.invokeLater(new Runnable() {//swing components are not thread safe, this will run on Swings event dispatch thread
|
||||
public void run() {
|
||||
XpathManager.nextXpathMatch(results, textPane, lblStatus, true);
|
||||
cmbXpath.setSelectedItem(results);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski7@gmail.com
|
||||
*/
|
||||
|
||||
package org.synthuse;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski
|
||||
*/
|
||||
|
||||
package org.synthuse.commands;
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski
|
||||
*/
|
||||
|
||||
package org.synthuse.commands;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski
|
||||
*/
|
||||
|
||||
package org.synthuse.commands;
|
||||
|
||||
import org.synthuse.*;
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski
|
||||
*/
|
||||
|
||||
package org.synthuse.commands;
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski
|
||||
*/
|
||||
|
||||
package org.synthuse.commands;
|
||||
|
||||
import java.awt.Point;
|
||||
@@ -18,9 +25,9 @@ public class MouseCommands extends BaseCommand {
|
||||
if (handle.isEmpty())
|
||||
return false;
|
||||
String wtype = getWindowTypeWithXpath(args[0]);
|
||||
System.out.println("wtype: " + wtype + " hwnd " + handle.hWnd + " hmenu " + handle.hmenuStr + " pos " + handle.hmenuPos);
|
||||
//System.out.println("wtype: " + wtype + " hwnd " + handle.hWnd + " hmenu " + handle.hmenuStr + " pos " + handle.hmenuPos);
|
||||
Point p = getCenterWindowPosition(handle, wtype);
|
||||
System.out.println("cmdClick: " + p.x + "," + p.y);
|
||||
//System.out.println("cmdClick: " + p.x + "," + p.y);
|
||||
RobotMacro.mouseMove(p.x + parentProcessor.targetOffset.x, p.y + parentProcessor.targetOffset.y);
|
||||
RobotMacro.leftClickMouse();
|
||||
return true;
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
/*
|
||||
* Copyright 2014, Synthuse.org
|
||||
* Released under the Apache Version 2.0 License.
|
||||
*
|
||||
* last modified by ejakubowski
|
||||
*/
|
||||
|
||||
package org.synthuse.commands;
|
||||
|
||||
import org.synthuse.*;
|
||||
@@ -152,4 +159,22 @@ public class WindowsCommands extends BaseCommand {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean cmdSendCommandMsg(String[] args) {
|
||||
if (!checkArgumentLength(args, 3))
|
||||
return false;
|
||||
WinPtr handle = findHandleWithXpath(args[0]); //xpath to HWND is first argument
|
||||
if (handle.isEmpty())
|
||||
return false;
|
||||
int id = Integer.parseInt(args[1]); //context menu id is supplied as second argument
|
||||
int idLparam = Integer.parseInt(args[2]); //context menu id is supplied as second argument
|
||||
handle.convertToNativeHwnd();
|
||||
//LRESULT result =
|
||||
//System.out.println("Send Message WM_COMMAND to " + handle.toString() + " PARAMS: " + id + ", " + idLparam);
|
||||
//api.user32.PostMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0));
|
||||
api.user32.SendMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(idLparam));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user