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);
int GetWindowRect(HWND hWnd, RECT r);
int MapWindowPoints(HWND hWndFrom, HWND hWndTo, RECT r, int cPoints);
HWND GetDesktopWindow();
HDC GetWindowDC(HWND hWnd);
int ReleaseDC(HWND hWnd, HDC hDC);
boolean InvalidateRect(HWND hWnd, long lpRect, boolean bErase);
@@ -339,6 +341,17 @@ public class Api {
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() {
return getDiskUsedPercentage(null);
}

View File

@@ -56,13 +56,13 @@ public class CommandPopupMenu extends JPopupMenu {
JMenu mnMouse = new JMenu("Mouse");
add(mnMouse);
CommandMenuItem mntmClick = new CommandMenuItem("click", 1, false);
CommandMenuItem mntmClick = new CommandMenuItem("click", 2, true);
mnMouse.add(mntmClick);
CommandMenuItem mntmDoubleclick = new CommandMenuItem("doubleClick", 1, false);
CommandMenuItem mntmDoubleclick = new CommandMenuItem("doubleClick", 2, true);
mnMouse.add(mntmDoubleclick);
CommandMenuItem mntmRightclick = new CommandMenuItem("rightClick", 1, false);
CommandMenuItem mntmRightclick = new CommandMenuItem("rightClick", 2, true);
mnMouse.add(mntmRightclick);
CommandMenuItem mntmwinClick = new CommandMenuItem("winClick", 2);
@@ -89,9 +89,15 @@ public class CommandPopupMenu extends JPopupMenu {
CommandMenuItem mntmMouseupright = new CommandMenuItem("mouseUpRight", 1, false);
mnMouse.add(mntmMouseupright);
CommandMenuItem mntmMousemove = new CommandMenuItem("mouseMove", 3, false);
CommandMenuItem mntmMousemove = new CommandMenuItem("mouseMove", 2, true);
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");
add(mnWinMessages);

View File

@@ -7,6 +7,7 @@
package org.synthuse;
import java.awt.Point;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Timestamp;
@@ -31,6 +32,7 @@ public class CommandProcessor implements Runnable{
public String lastError = "";
public String scriptStr = "";
private Api api = new Api();
private Point targetOffset = new Point();
private int executeErrorCount = 0;
private String currentCommandText = "";
@@ -167,6 +169,10 @@ public class CommandProcessor implements Runnable{
return cmdMouseUpRight(args);
if (command.equals("mouseMove"))
return cmdMouseMove(args);
if (command.equals("mouseMoveXy"))
return cmdMouseMoveXy(args);
if (command.equals("setTargetOffset"))
return cmdSetTargetOffset(args);
//Windows Api Commands
if (command.equals("windowFocus"))
@@ -334,16 +340,37 @@ public class CommandProcessor implements Runnable{
}
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();
return true;
}
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();
return true;
}
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();
return true;
}
@@ -369,6 +396,27 @@ public class CommandProcessor implements Runnable{
}
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))
return false;
int x = Integer.parseInt(args[0]);