Added SelectContextMenuId Command, increasing uiabridge speeds, reliability
This commit is contained in:
@@ -15,9 +15,11 @@ 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.ULONG_PTR;
|
||||
import com.sun.jna.platform.win32.WinDef;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinReg;
|
||||
import com.sun.jna.platform.win32.WinUser;
|
||||
import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER;
|
||||
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;
|
||||
@@ -133,6 +135,11 @@ public class Api {
|
||||
return (int) (i & 0xFFFF);
|
||||
}
|
||||
|
||||
public static long MAKELONG(int low, int high)
|
||||
{
|
||||
return ((long)(((short)((int)(low) & 0xffff)) | ((int)((short)((int)(high) & 0xffff))) << 16));
|
||||
}
|
||||
|
||||
public interface WinDefExt extends WinDef {
|
||||
//Structures
|
||||
public class MENUITEMINFO extends Structure {
|
||||
@@ -235,6 +242,7 @@ public class Api {
|
||||
//HWND WindowFromPoint(POINT point);
|
||||
|
||||
HMENU GetMenu(HWND hWnd);
|
||||
HMENU GetSystemMenu(HWND hWnd, boolean bRevert);
|
||||
boolean IsMenu(HMENU hMenu);
|
||||
int GetMenuString(HMENU hMenu, int uIDItem, char[] buffer, int nMaxCount, int uFlag);
|
||||
HMENU GetSubMenu(HMENU hMenu, int nPos);
|
||||
@@ -243,7 +251,7 @@ public class Api {
|
||||
//BOOL WINAPI GetMenuItemInfo(_In_ HMENU hMenu, _In_ UINT uItem, _In_ BOOL fByPosition, _Inout_ LPMENUITEMINFO lpmii);
|
||||
boolean GetMenuItemInfoA(HMENU hMenu, int uItem, boolean fByPosition, WinDefExt.MENUITEMINFO mii); //MENUITEMINFO
|
||||
boolean TrackPopupMenu(HMENU hMenu, int uFlags, int x, int y, int nReserved, HWND hWnd, long prcRect);
|
||||
//
|
||||
boolean GetMenuItemRect(HWND hWnd, HMENU hMenu, int uItem, RECT rect);
|
||||
|
||||
int GetDlgCtrlID(HWND hwndCtl);
|
||||
int GetDlgItemText(HWND hDlg, int nIDDlgItem, byte[] buffer, int nMaxCount);
|
||||
@@ -536,4 +544,10 @@ public class Api {
|
||||
User32.instance.RedrawWindow(hwnd, 0, 0, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
|
||||
}
|
||||
|
||||
public static boolean isDotNet4Installed() {
|
||||
int installed = Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4.0\\Client", "Install");
|
||||
//System.out.println("isDotNet4Installed: " + installed);
|
||||
return (installed == 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -109,6 +109,9 @@ public class CommandPopupMenu extends JPopupMenu {
|
||||
|
||||
CommandMenuItem mntmSelectMenu = new CommandMenuItem("selectMenu", 2);
|
||||
mnWinMessages.add(mntmSelectMenu);
|
||||
|
||||
CommandMenuItem mntmSelectContextMenuId = new CommandMenuItem("selectContextMenuId", 3);
|
||||
mnWinMessages.add(mntmSelectContextMenuId);
|
||||
|
||||
CommandMenuItem mntmSetcursorposition = new CommandMenuItem("setCursorPosition", 3);
|
||||
mnWinMessages.add(mntmSetcursorposition);
|
||||
|
||||
@@ -205,6 +205,8 @@ public class CommandProcessor implements Runnable{
|
||||
return win.cmdWindowFocus(args);
|
||||
if (command.equals("selectMenu"))
|
||||
return win.cmdSelectMenu(args);
|
||||
if (command.equals("selectContextMenuId"))
|
||||
return win.cmdSelectContextMenuId(args);
|
||||
if (command.equals("windowMinimize"))
|
||||
return win.cmdWindowMinimize(args);
|
||||
if (command.equals("windowMaximize"))
|
||||
|
||||
@@ -131,7 +131,7 @@ public class KeyboardHook implements Runnable{
|
||||
}
|
||||
|
||||
// search target keyboard event list for a match and return it otherwise return null if no match
|
||||
public TargetKeyPress getTargetKeyPressed(int keyCode) {
|
||||
private TargetKeyPress getTargetKeyPressed(int keyCode) {
|
||||
TargetKeyPress target = null;
|
||||
for (TargetKeyPress tkp : KeyboardHook.targetList) {
|
||||
if (tkp.targetKeyCode != keyCode)
|
||||
@@ -159,6 +159,7 @@ public class KeyboardHook implements Runnable{
|
||||
@Override
|
||||
public void run() {
|
||||
createGlobalKeyboardHook();
|
||||
System.out.println("Unhooking Global Keyboard Hook");
|
||||
unhook();//wait for quit == true then unhook
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ package org.synthuse;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinDef.HMENU;
|
||||
import com.sun.jna.platform.win32.WinDef.*;
|
||||
|
||||
public class MenuInfo {
|
||||
public HMENU hmenu = null;
|
||||
@@ -25,12 +25,15 @@ public class MenuInfo {
|
||||
public HMENU submenu = null;
|
||||
public String submenuStr = "";
|
||||
public int submenuCount = 0;
|
||||
public String center = "";
|
||||
|
||||
public MenuInfo(HMENU hmenu) {
|
||||
public MenuInfo(String hwndStr, HMENU hmenu) {
|
||||
this.hwndStr = hwndStr;
|
||||
loadMenuBase(hmenu);
|
||||
}
|
||||
|
||||
public MenuInfo(HMENU hmenu, int position) {
|
||||
public MenuInfo(String hwndStr, HMENU hmenu, int position) {
|
||||
this.hwndStr = hwndStr;
|
||||
loadMenuBase(hmenu);
|
||||
if (this.menuCount > 0)
|
||||
loadMenuDetails(hmenu, position);
|
||||
@@ -52,6 +55,14 @@ public class MenuInfo {
|
||||
this.text = this.text.substring(0, this.text.indexOf("\t"));
|
||||
this.text = text.replaceAll("[^a-zA-Z0-9.,\\+ ]", "");
|
||||
this.id = api.user32.GetMenuItemID(hmenu, position);
|
||||
/*
|
||||
HWND hWnd = Api.GetHandleFromString(hwndStr);
|
||||
RECT rect = new RECT();
|
||||
api.user32.GetMenuItemRect(hWnd, hmenu, position, rect);
|
||||
int centerX = ((rect.right - rect.left) / 2) + rect.left;
|
||||
int centerY = ((rect.bottom - rect.top) / 2) + rect.top;
|
||||
this.center = centerX + "," + centerY;
|
||||
*/
|
||||
HMENU submenu = api.user32.GetSubMenu(hmenu, position);
|
||||
if (submenu != null) {
|
||||
int subCount = api.user32.GetMenuItemCount(submenu);
|
||||
|
||||
@@ -68,7 +68,7 @@ public class RobotMacro {
|
||||
|
||||
public static void rightClickMouse() {
|
||||
try {
|
||||
System.out.println("rightClickMouse");
|
||||
//System.out.println("rightClickMouse");
|
||||
Robot robot = new Robot();
|
||||
//robot.mouseMove(200, 200);
|
||||
//robot.delay(1000);
|
||||
|
||||
@@ -71,7 +71,7 @@ public class SynthuseDlg extends JFrame {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String VERSION_STR = "1.1.3";
|
||||
public static String VERSION_STR = "1.1.4";
|
||||
|
||||
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";
|
||||
|
||||
@@ -6,8 +6,13 @@ import java.io.*;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class UiaBridge {
|
||||
|
||||
public static String CACHED_PROPERTY_LIST = "RuntimeIdProperty,ParentRuntimeIdProperty,ProcessIdProperty,FrameworkIdProperty,LocalizedControlTypeProperty,ClassNameProperty,NameProperty,ValueProperty,BoundingRectangleProperty";
|
||||
|
||||
static
|
||||
{
|
||||
if (!Api.isDotNet4Installed()) //if .net 4.0 isn't installed don't use uiabridge
|
||||
SynthuseDlg.config.disableUiaBridge = "true";
|
||||
if (!SynthuseDlg.config.isUiaBridgeDisabled()) {
|
||||
//System.out.println("SynthuseDlg.config.disableUiaBridge: " + SynthuseDlg.config.disableUiaBridge);
|
||||
String archDataModel = System.getProperty("sun.arch.data.model");//32 or 64 bit
|
||||
@@ -78,7 +83,7 @@ public class UiaBridge {
|
||||
public UiaBridge ()
|
||||
{
|
||||
if (!SynthuseDlg.config.isUiaBridgeDisabled())
|
||||
initialize("");
|
||||
initialize(CACHED_PROPERTY_LIST);
|
||||
}
|
||||
|
||||
public native void initialize(String properties);
|
||||
|
||||
@@ -26,6 +26,7 @@ public class WindowInfo {
|
||||
|
||||
public static String UIA_PROPERTY_LIST = "RuntimeIdProperty,ParentRuntimeIdProperty,ProcessIdProperty,FrameworkIdProperty,LocalizedControlTypeProperty,ClassNameProperty,NameProperty,ValueProperty";
|
||||
public static String UIA_RUNTIME_ID = "RuntimeIdProperty";
|
||||
public static String UIA_BOUNDING_RECT = "BoundingRectangleProperty";
|
||||
public static int MAX_TEXT_SIZE = 200;
|
||||
|
||||
public HWND hwnd;
|
||||
@@ -96,23 +97,7 @@ public class WindowInfo {
|
||||
extra = new LinkedHashMap<String, String>();
|
||||
extra.put("tvCount", tvCount.intValue() + "");
|
||||
}
|
||||
|
||||
//check if window has a menu
|
||||
HMENU hmenu = Api.User32.instance.GetMenu(hWnd);
|
||||
if (hmenu != null) { //menu item count
|
||||
int menuCount = Api.User32.instance.GetMenuItemCount(hmenu);
|
||||
if (menuCount > 0) {
|
||||
this.menus = menuCount;
|
||||
this.menu = hmenu;
|
||||
}
|
||||
else
|
||||
{
|
||||
LRESULT result = Api.User32.instance.PostMessage(hWnd, Api.MN_GETHMENU, new WPARAM(0), new LPARAM());
|
||||
if (result.longValue() != 1)
|
||||
System.out.println("MN_GETHMENU: " + result.longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (isChild) {
|
||||
int ctrlID = Api.User32.instance.GetDlgCtrlID(hWnd);
|
||||
if (ctrlID > 0){
|
||||
@@ -125,12 +110,40 @@ public class WindowInfo {
|
||||
extra.put("dgText", dgText + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
char[] buffer2 = new char[1026];
|
||||
User32.instance.GetClassName(hWnd, buffer2, 1026);
|
||||
className = Native.toString(buffer2);
|
||||
|
||||
//check if window has a menu
|
||||
HMENU hmenu = Api.User32.instance.GetMenu(hWnd);
|
||||
if (hmenu != null) { //menu item count
|
||||
int menuCount = Api.User32.instance.GetMenuItemCount(hmenu);
|
||||
if (menuCount > 0) {
|
||||
this.menus = menuCount;
|
||||
this.menu = hmenu;
|
||||
}
|
||||
}
|
||||
else // if (className.equals("#32768")) //check if its a popup menu window
|
||||
{
|
||||
//LRESULT result = Api.User32.instance.PostMessage(hWnd, Api.MN_GETHMENU, new WPARAM(0), new LPARAM(0));
|
||||
LRESULT result = Api.User32.instance.SendMessage(hWnd, Api.MN_GETHMENU, new WPARAM(0), new LPARAM(0));
|
||||
if (result.longValue() != 1)
|
||||
{
|
||||
//System.out.println("MN_GETHMENU: " + result.longValue());
|
||||
hmenu = new HMENU(new Pointer(result.longValue()));
|
||||
int menuCount = Api.User32.instance.GetMenuItemCount(hmenu);
|
||||
if (menuCount > 0)
|
||||
{
|
||||
//System.out.println("Popup Win: " + menuCount);
|
||||
this.menus = menuCount;
|
||||
this.menu = hmenu;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rect = new RECT();
|
||||
User32.instance.GetWindowRect(hWnd, rect);
|
||||
|
||||
|
||||
@@ -249,16 +249,18 @@ public class WindowsEnumeratedXml implements Runnable{
|
||||
|
||||
public static Element buildMenuXmlElements(Document xmlDoc, Element xmlElement, HMENU targetMenu, String targetWin)
|
||||
{
|
||||
MenuInfo firstMi = new MenuInfo(targetMenu);
|
||||
MenuInfo firstMi = new MenuInfo(targetWin, targetMenu);
|
||||
for (int i = 0 ; i < firstMi.menuCount ; i++ ) {
|
||||
MenuInfo menuInfo = new MenuInfo(targetMenu, i);
|
||||
MenuInfo menuInfo = new MenuInfo(targetWin, targetMenu, i);
|
||||
Element menuElement = xmlDoc.createElement("menu");
|
||||
menuElement.setAttribute("unaltered", menuInfo.unaltered + "");
|
||||
menuElement.setAttribute("text", menuInfo.text + "");
|
||||
menuElement.setAttribute("id", menuInfo.id + "");
|
||||
menuElement.setAttribute("position", menuInfo.position + "");
|
||||
menuElement.setAttribute("hmenu", menuInfo.hmenuStr + "");
|
||||
menuElement.setAttribute("hwnd", targetWin + "");
|
||||
menuElement.setAttribute("hwnd", menuInfo.hwndStr + "");
|
||||
if (!menuInfo.center.isEmpty())
|
||||
menuElement.setAttribute("center", menuInfo.center + "");
|
||||
if (menuInfo.hasSubMenu) {
|
||||
buildMenuXmlElements(xmlDoc, menuElement, menuInfo.submenu, targetWin);
|
||||
}
|
||||
|
||||
@@ -122,6 +122,22 @@ public class WindowsCommands extends BaseCommand {
|
||||
//LRESULT result =
|
||||
//System.out.println("PostMessage to " + handle.hWndStr + " for id " + id);
|
||||
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(0));
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean cmdSelectContextMenuId(String[] args) {
|
||||
if (!checkArgumentLength(args, 2))
|
||||
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
|
||||
//LRESULT result =
|
||||
System.out.println("PostMessage to " + handle.toString() + " for id " + id + " - " + Api.MAKELONG(id, 0));
|
||||
//api.user32.PostMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0));
|
||||
api.user32.SendMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(Api.MAKELONG(id, 0)), new LPARAM(0));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user