diff --git a/src/main/java/xyz/wbsite/jmacro/JMacro.java b/src/main/java/xyz/wbsite/jmacro/JMacro.java index a98419b..dcaac89 100644 --- a/src/main/java/xyz/wbsite/jmacro/JMacro.java +++ b/src/main/java/xyz/wbsite/jmacro/JMacro.java @@ -149,13 +149,19 @@ public abstract class JMacro { * @param location 坐标点 */ public void mouseMove(Location location) { + // 判断当前鼠标位置和需要移动的位置是否是同一个点 + if (Mouse.at().x == location.getX() && Mouse.at().y == location.getY()) { + Logger.info("鼠标位置在目标位置,不需移动"); + return; + } + List path = MousePathUtil.generateBezierPath(Mouse.at(), location); Settings.MoveMouseDelay = 0.0f; // 暂停点索引(-1为不暂停) int pause = -1; // 通过概率决断本次是否需要产生拐点(按50%概率) - if (RandomUtil.randomInt(0, 100) < 50) { + if (path.size() > 30 && RandomUtil.randomInt(0, 100) < 50) { // 拐点从路径的1/3到2/3随机选择 int startIdx = path.size() / 3; int endIdx = 2 * path.size() / 3; @@ -238,7 +244,7 @@ public abstract class JMacro { * 鼠标右键单击 */ public void mouseRightClick() { - mouseRightClick(Mouse.at()); + Mouse.at().rightClick(); } /** @@ -549,10 +555,28 @@ public abstract class JMacro { * @return 随机中心坐标 */ public Location randomCenter(Region region) { + int x1 = Mouse.at().getX(); + int y1 = Mouse.at().getY(); + // 随机移动到区域中心附近(而非直接移动到中心) Location center = region.getCenter(); // 得到随机移动到区域中心附近的半径 int radius = (int) (Math.min(region.getW(), region.getH()) / 2 * 0.9f); + + // 如果半径过小,则直接返回中心点 + if (radius <= 0) { + return center; + } + + // 中心坐标 + int cx = center.getX(); + int cy = center.getY(); + + // 判断鼠标是否在区域中心以内 + if (x1 >= cx - radius && x1 <= cx + radius && y1 >= cy - radius && y1 <= cy + radius) { + return Mouse.at(); + } + int x = center.getX() + RandomUtil.randomInt(-radius, radius); int y = center.getY() + RandomUtil.randomInt(-radius, radius); return new Location(x, y); diff --git a/src/main/java/xyz/wbsite/jmacro/util/MousePathUtil.java b/src/main/java/xyz/wbsite/jmacro/util/MousePathUtil.java index da6df8c..bc60a18 100644 --- a/src/main/java/xyz/wbsite/jmacro/util/MousePathUtil.java +++ b/src/main/java/xyz/wbsite/jmacro/util/MousePathUtil.java @@ -47,12 +47,7 @@ public class MousePathUtil { * @return 轨迹点集合 */ public static List generateBezierPath(Location start, Location end) { - int x0 = start.x, y0 = start.y; - int x1 = end.x, y1 = end.y; - // 随机生成控制点,增加不确定性(避免总是直线) - int controlX = (x0 + x1) / 2 + random.nextInt(200) - 100; - int controlY = (y0 + y1) / 2 + random.nextInt(200) - 100; - return generateBezierPath(x0, y0, controlX, controlY, x1, y1); + return generateBezierPath(start.x, start.y, end.x, end.y); } /**