Fixed context menu click, added more sendkeys, fix for global key hook
This commit is contained in:
@@ -91,6 +91,39 @@ public class BaseCommand {
|
||||
appendError("Error: command '" + getCurrentCommand() + "' failed");
|
||||
return cmdResult;
|
||||
}
|
||||
|
||||
public void forceXmlRefresh() {
|
||||
WIN_XML = WindowsEnumeratedXml.getXml();
|
||||
LAST_UPDATED_XML = System.nanoTime();
|
||||
}
|
||||
|
||||
public String getWindowTypeWithXpath(String xpath) {
|
||||
String result = "";
|
||||
double secondsFromLastUpdate = ((double)(System.nanoTime() - LAST_UPDATED_XML) / 1000000000);
|
||||
if (secondsFromLastUpdate > CommandProcessor.XML_UPDATE_THRESHOLD) { //default 5 second threshold
|
||||
WIN_XML = WindowsEnumeratedXml.getXml();
|
||||
LAST_UPDATED_XML = System.nanoTime();
|
||||
}
|
||||
String resultStr = "";
|
||||
List<String> resultList = WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
|
||||
if (resultList.size() > 0)
|
||||
{
|
||||
resultStr = resultList.get(0).trim();
|
||||
if (resultStr.startsWith("<winfrm "))
|
||||
result = "winfrm";
|
||||
else if(resultStr.startsWith("<win "))
|
||||
result = "win";
|
||||
else if(resultStr.startsWith("<wpf "))
|
||||
result = "wpf";
|
||||
else if(resultStr.startsWith("<silver "))
|
||||
result = "silver";
|
||||
else if(resultStr.startsWith("<menu "))
|
||||
result = "menu";
|
||||
else
|
||||
result = "other";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public WinPtr findHandleWithXpath(String xpath) {
|
||||
return findHandleWithXpath(xpath, false);
|
||||
@@ -103,10 +136,11 @@ public class BaseCommand {
|
||||
WIN_XML = WindowsEnumeratedXml.getXml();
|
||||
LAST_UPDATED_XML = System.nanoTime();
|
||||
}
|
||||
WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
|
||||
//WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
|
||||
String resultStr = "";
|
||||
List<String> resultList = WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
|
||||
for(String item: resultList) {
|
||||
//System.out.println("xpath result item: " + item);
|
||||
if (item.contains("hwnd=")) {
|
||||
List<String> hwndList = WindowsEnumeratedXml.evaluateXpathGetValues(item, "//@hwnd");
|
||||
if (hwndList.size() > 0)
|
||||
@@ -114,8 +148,19 @@ public class BaseCommand {
|
||||
}
|
||||
else
|
||||
resultStr = item;
|
||||
break;
|
||||
if (item.contains("hmenu=")) { //get menu information, useful for getting center of menu
|
||||
List<String> hmenuList = WindowsEnumeratedXml.evaluateXpathGetValues(item, "//@hmenu");
|
||||
if (hmenuList.size() > 0)
|
||||
result.hmenuStr = hmenuList.get(0).replaceAll("[^\\d-.]", ""); //get first hmenu;
|
||||
if (item.contains("id=")) {
|
||||
List<String> menuidList = WindowsEnumeratedXml.evaluateXpathGetValues(item, "//@position");
|
||||
if (menuidList.size() > 0)
|
||||
result.hmenuPos = Integer.parseInt(menuidList.get(0).replaceAll("[^\\d-.]", "")); //get first id;
|
||||
}
|
||||
}
|
||||
break;// we only care about the first item
|
||||
}
|
||||
|
||||
resultStr = resultStr.replaceAll("[^\\d-.]", ""); //remove all non-numeric values (except dash -)
|
||||
if (WinPtr.isWpfRuntimeIdFormat(resultStr)) {
|
||||
result.runtimeId = resultStr;
|
||||
@@ -137,7 +182,7 @@ public class BaseCommand {
|
||||
WIN_XML = WindowsEnumeratedXml.getXml();
|
||||
LAST_UPDATED_XML = System.nanoTime();
|
||||
}
|
||||
WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
|
||||
//WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
|
||||
String resultStr = "";
|
||||
List<String> resultList = WindowsEnumeratedXml.evaluateXpathGetValues(WIN_XML, xpath);
|
||||
for(String item: resultList) {
|
||||
@@ -169,6 +214,18 @@ public class BaseCommand {
|
||||
return p;
|
||||
}
|
||||
|
||||
public Point getCenterWindowPosition(WinPtr handle, String windowType) {
|
||||
Point p = null;
|
||||
|
||||
if (handle.isWpf() || windowType.equals("winfrm") || windowType.equals("wpf") || windowType.equals("silver"))
|
||||
p = uiabridge.getCenterOfElement(handle.runtimeId);
|
||||
else if (windowType.equals("win"))
|
||||
p = api.getWindowPosition(handle.hWnd);
|
||||
else if (windowType.equals("menu"))
|
||||
p = api.getMenuItemPosition(handle.hWnd, MenuInfo.GetHandleMenuFromString(handle.hmenuStr), handle.hmenuPos);
|
||||
return p;
|
||||
}
|
||||
|
||||
public String convertListToString(List<String> listStr, String delimiter) {
|
||||
StringBuilder result = new StringBuilder("");
|
||||
for (String item: listStr) {
|
||||
|
||||
@@ -23,9 +23,10 @@ public class MainCommands extends BaseCommand {
|
||||
public boolean cmdDisplayText(String[] args) throws IOException {
|
||||
if (!checkArgumentLength(args, 2))
|
||||
return false;
|
||||
if (!checkIsNumeric(args[1]))
|
||||
if (!checkIsNumeric(args[1])) //arg[1] is in milliseconds
|
||||
return false;
|
||||
this.killStatusWindow();
|
||||
//System.out.println("StatusWindow " + args[0] + ", " + Integer.parseInt(args[1]));
|
||||
StatusWindow sw = new StatusWindow(args[0], Integer.parseInt(args[1]));
|
||||
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
sw.setLocation(dim.width/2-sw.getSize().width/2, dim.height + StatusWindow.Y_BOTTOM_OFFSET - 80 );
|
||||
@@ -48,6 +49,21 @@ public class MainCommands extends BaseCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean cmdSetUpdateThreshold(String[] args) {
|
||||
if (!checkArgumentLength(args, 1))
|
||||
return false;
|
||||
long threshold = Long.parseLong(args[0]);
|
||||
CommandProcessor.XML_UPDATE_THRESHOLD = threshold;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean cmdForceRefresh(String[] args) {
|
||||
if (!checkArgumentLength(args, 0))
|
||||
return false;
|
||||
forceXmlRefresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean cmdWaitForTitle(String[] args) {
|
||||
if (!checkArgumentLength(args, 1))
|
||||
return false;
|
||||
|
||||
@@ -17,8 +17,10 @@ public class MouseCommands extends BaseCommand {
|
||||
//System.out.println("cmdClick1: " + args[0]);
|
||||
if (handle.isEmpty())
|
||||
return false;
|
||||
Point p = getCenterWindowPosition(handle);
|
||||
//System.out.println("cmdClick3: " + p.x + "," + p.y);
|
||||
String wtype = getWindowTypeWithXpath(args[0]);
|
||||
//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);
|
||||
RobotMacro.mouseMove(p.x + parentProcessor.targetOffset.x, p.y + parentProcessor.targetOffset.y);
|
||||
RobotMacro.leftClickMouse();
|
||||
return true;
|
||||
@@ -30,7 +32,8 @@ public class MouseCommands extends BaseCommand {
|
||||
WinPtr handle = findHandleWithXpath(args[0]);
|
||||
if (handle.isEmpty())
|
||||
return false;
|
||||
Point p = getCenterWindowPosition(handle);
|
||||
String wtype = getWindowTypeWithXpath(args[0]);
|
||||
Point p = getCenterWindowPosition(handle, wtype);
|
||||
RobotMacro.mouseMove(p.x + parentProcessor.targetOffset.x, p.y + parentProcessor.targetOffset.y);
|
||||
RobotMacro.doubleClickMouse();
|
||||
return true;
|
||||
@@ -42,7 +45,8 @@ public class MouseCommands extends BaseCommand {
|
||||
WinPtr handle = findHandleWithXpath(args[0]);
|
||||
if (handle.isEmpty())
|
||||
return false;
|
||||
Point p = getCenterWindowPosition(handle);
|
||||
String wtype = getWindowTypeWithXpath(args[0]);
|
||||
Point p = getCenterWindowPosition(handle, wtype);
|
||||
RobotMacro.mouseMove(p.x + parentProcessor.targetOffset.x, p.y + parentProcessor.targetOffset.y);
|
||||
RobotMacro.rightClickMouse();
|
||||
return true;
|
||||
@@ -74,7 +78,8 @@ public class MouseCommands extends BaseCommand {
|
||||
WinPtr handle = findHandleWithXpath(args[0]);
|
||||
if (handle.isEmpty())
|
||||
return false;
|
||||
Point p = getCenterWindowPosition(handle);
|
||||
String wtype = getWindowTypeWithXpath(args[0]);
|
||||
Point p = getCenterWindowPosition(handle, wtype);
|
||||
RobotMacro.mouseMove(p.x + parentProcessor.targetOffset.x, p.y + parentProcessor.targetOffset.y);
|
||||
//System.out.println("point " + p.x + "," + p.y);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user