updates to mouse commands

Added setTargetOffset, and mouse will move to target window for click,
rightclick and double click
This commit is contained in:
Edward Jakubowski
2014-03-21 01:10:06 -04:00
parent 4f65c0b921
commit 1b33ca6de0
3 changed files with 72 additions and 5 deletions

View File

@@ -130,6 +130,8 @@ public class Api {
boolean IsWindowVisible(HWND hWnd); boolean IsWindowVisible(HWND hWnd);
int GetWindowRect(HWND hWnd, RECT r); int GetWindowRect(HWND hWnd, RECT r);
int MapWindowPoints(HWND hWndFrom, HWND hWndTo, RECT r, int cPoints);
HWND GetDesktopWindow();
HDC GetWindowDC(HWND hWnd); HDC GetWindowDC(HWND hWnd);
int ReleaseDC(HWND hWnd, HDC hDC); int ReleaseDC(HWND hWnd, HDC hDC);
boolean InvalidateRect(HWND hWnd, long lpRect, boolean bErase); boolean InvalidateRect(HWND hWnd, long lpRect, boolean bErase);
@@ -339,6 +341,17 @@ public class Api {
user32.SendMessageA(handle, WM_KEYUP, keyCode, null); user32.SendMessageA(handle, WM_KEYUP, keyCode, null);
} }
public Point getWindowPosition(HWND handle) {
Point windowPoint = new Point();
RECT rect = new RECT();
user32.GetWindowRect(handle, rect);
//System.out.println("rect: l" + rect.left + ",t" + rect.top + ",r" + rect.right + ",b" + rect.bottom);
//user32.MapWindowPoints(user32.GetDesktopWindow(), user32.GetParent(handle), rect, 2);
windowPoint.x = ((rect.right - rect.left) / 2) + rect.left;
windowPoint.y = ((rect.bottom - rect.top) / 2) + rect.top;
return windowPoint;
}
public int getDiskUsedPercentage() { public int getDiskUsedPercentage() {
return getDiskUsedPercentage(null); return getDiskUsedPercentage(null);
} }

View File

@@ -56,13 +56,13 @@ public class CommandPopupMenu extends JPopupMenu {
JMenu mnMouse = new JMenu("Mouse"); JMenu mnMouse = new JMenu("Mouse");
add(mnMouse); add(mnMouse);
CommandMenuItem mntmClick = new CommandMenuItem("click", 1, false); CommandMenuItem mntmClick = new CommandMenuItem("click", 2, true);
mnMouse.add(mntmClick); mnMouse.add(mntmClick);
CommandMenuItem mntmDoubleclick = new CommandMenuItem("doubleClick", 1, false); CommandMenuItem mntmDoubleclick = new CommandMenuItem("doubleClick", 2, true);
mnMouse.add(mntmDoubleclick); mnMouse.add(mntmDoubleclick);
CommandMenuItem mntmRightclick = new CommandMenuItem("rightClick", 1, false); CommandMenuItem mntmRightclick = new CommandMenuItem("rightClick", 2, true);
mnMouse.add(mntmRightclick); mnMouse.add(mntmRightclick);
CommandMenuItem mntmwinClick = new CommandMenuItem("winClick", 2); CommandMenuItem mntmwinClick = new CommandMenuItem("winClick", 2);
@@ -89,8 +89,14 @@ public class CommandPopupMenu extends JPopupMenu {
CommandMenuItem mntmMouseupright = new CommandMenuItem("mouseUpRight", 1, false); CommandMenuItem mntmMouseupright = new CommandMenuItem("mouseUpRight", 1, false);
mnMouse.add(mntmMouseupright); mnMouse.add(mntmMouseupright);
CommandMenuItem mntmMousemove = new CommandMenuItem("mouseMove", 3, false); CommandMenuItem mntmMousemove = new CommandMenuItem("mouseMove", 2, true);
mnMouse.add(mntmMousemove); mnMouse.add(mntmMousemove);
CommandMenuItem mntmMousemoveXy = new CommandMenuItem("mouseMoveXy", 3, false);
mnMouse.add(mntmMousemoveXy);
CommandMenuItem mntmSetTargetOffset = new CommandMenuItem("setTargetOffset", 3, false);
mnMouse.add(mntmSetTargetOffset);
JMenu mnWinMessages = new JMenu("Win Messages"); JMenu mnWinMessages = new JMenu("Win Messages");
add(mnWinMessages); add(mnWinMessages);

View File

@@ -7,6 +7,7 @@
package org.synthuse; package org.synthuse;
import java.awt.Point;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.sql.Timestamp; import java.sql.Timestamp;
@@ -31,6 +32,7 @@ public class CommandProcessor implements Runnable{
public String lastError = ""; public String lastError = "";
public String scriptStr = ""; public String scriptStr = "";
private Api api = new Api(); private Api api = new Api();
private Point targetOffset = new Point();
private int executeErrorCount = 0; private int executeErrorCount = 0;
private String currentCommandText = ""; private String currentCommandText = "";
@@ -165,8 +167,12 @@ public class CommandProcessor implements Runnable{
return cmdMouseDownRight(args); return cmdMouseDownRight(args);
if (command.equals("mouseUpRight")) if (command.equals("mouseUpRight"))
return cmdMouseUpRight(args); return cmdMouseUpRight(args);
if (command.equals("mouseMove")) if (command.equals("mouseMove"))
return cmdMouseMove(args); return cmdMouseMove(args);
if (command.equals("mouseMoveXy"))
return cmdMouseMoveXy(args);
if (command.equals("setTargetOffset"))
return cmdSetTargetOffset(args);
//Windows Api Commands //Windows Api Commands
if (command.equals("windowFocus")) if (command.equals("windowFocus"))
@@ -334,16 +340,37 @@ public class CommandProcessor implements Runnable{
} }
private boolean cmdClick(String[] args) { private boolean cmdClick(String[] args) {
if (!checkArgumentLength(args, 1))
return false;
HWND handle = findHandleWithXpath(args[0]);
if (handle == null)
return false;
Point p = api.getWindowPosition(handle);
RobotMacro.mouseMove(p.x + targetOffset.x, p.y + targetOffset.y);
RobotMacro.leftClickMouse(); RobotMacro.leftClickMouse();
return true; return true;
} }
private boolean cmdDoubleClick(String[] args) { private boolean cmdDoubleClick(String[] args) {
if (!checkArgumentLength(args, 1))
return false;
HWND handle = findHandleWithXpath(args[0]);
if (handle == null)
return false;
Point p = api.getWindowPosition(handle);
RobotMacro.mouseMove(p.x + targetOffset.x, p.y + targetOffset.y);
RobotMacro.doubleClickMouse(); RobotMacro.doubleClickMouse();
return true; return true;
} }
private boolean cmdRightClick(String[] args) { private boolean cmdRightClick(String[] args) {
if (!checkArgumentLength(args, 1))
return false;
HWND handle = findHandleWithXpath(args[0]);
if (handle == null)
return false;
Point p = api.getWindowPosition(handle);
RobotMacro.mouseMove(p.x + targetOffset.x, p.y + targetOffset.y);
RobotMacro.rightClickMouse(); RobotMacro.rightClickMouse();
return true; return true;
} }
@@ -369,6 +396,27 @@ public class CommandProcessor implements Runnable{
} }
private boolean cmdMouseMove(String[] args) { private boolean cmdMouseMove(String[] args) {
if (!checkArgumentLength(args, 1))
return false;
HWND handle = findHandleWithXpath(args[0]);
if (handle == null)
return false;
Point p = api.getWindowPosition(handle);
RobotMacro.mouseMove(p.x + targetOffset.x, p.y + targetOffset.y);
//System.out.println("point " + p.x + "," + p.y);
return true;
}
private boolean cmdSetTargetOffset(String[] args) {
if (!checkArgumentLength(args, 2))
return false;
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
targetOffset.x = x;
targetOffset.y = y;
return true;
}
private boolean cmdMouseMoveXy(String[] args) {
if (!checkArgumentLength(args, 2)) if (!checkArgumentLength(args, 2))
return false; return false;
int x = Integer.parseInt(args[0]); int x = Integer.parseInt(args[0]);