上传备份

master
王兵 1 week ago
parent 691d1fe652
commit 73f7a894c9

@ -149,13 +149,19 @@ public abstract class JMacro {
* @param location * @param location
*/ */
public void mouseMove(Location location) { public void mouseMove(Location location) {
// 判断当前鼠标位置和需要移动的位置是否是同一个点
if (Mouse.at().x == location.getX() && Mouse.at().y == location.getY()) {
Logger.info("鼠标位置在目标位置,不需移动");
return;
}
List<int[]> path = MousePathUtil.generateBezierPath(Mouse.at(), location); List<int[]> path = MousePathUtil.generateBezierPath(Mouse.at(), location);
Settings.MoveMouseDelay = 0.0f; Settings.MoveMouseDelay = 0.0f;
// 暂停点索引(-1为不暂停 // 暂停点索引(-1为不暂停
int pause = -1; int pause = -1;
// 通过概率决断本次是否需要产生拐点按50%概率) // 通过概率决断本次是否需要产生拐点按50%概率)
if (RandomUtil.randomInt(0, 100) < 50) { if (path.size() > 30 && RandomUtil.randomInt(0, 100) < 50) {
// 拐点从路径的1/3到2/3随机选择 // 拐点从路径的1/3到2/3随机选择
int startIdx = path.size() / 3; int startIdx = path.size() / 3;
int endIdx = 2 * path.size() / 3; int endIdx = 2 * path.size() / 3;
@ -238,7 +244,7 @@ public abstract class JMacro {
* *
*/ */
public void mouseRightClick() { public void mouseRightClick() {
mouseRightClick(Mouse.at()); Mouse.at().rightClick();
} }
/** /**
@ -549,10 +555,28 @@ public abstract class JMacro {
* @return * @return
*/ */
public Location randomCenter(Region region) { public Location randomCenter(Region region) {
int x1 = Mouse.at().getX();
int y1 = Mouse.at().getY();
// 随机移动到区域中心附近(而非直接移动到中心) // 随机移动到区域中心附近(而非直接移动到中心)
Location center = region.getCenter(); Location center = region.getCenter();
// 得到随机移动到区域中心附近的半径 // 得到随机移动到区域中心附近的半径
int radius = (int) (Math.min(region.getW(), region.getH()) / 2 * 0.9f); 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 x = center.getX() + RandomUtil.randomInt(-radius, radius);
int y = center.getY() + RandomUtil.randomInt(-radius, radius); int y = center.getY() + RandomUtil.randomInt(-radius, radius);
return new Location(x, y); return new Location(x, y);

@ -47,12 +47,7 @@ public class MousePathUtil {
* @return * @return
*/ */
public static List<int[]> generateBezierPath(Location start, Location end) { public static List<int[]> generateBezierPath(Location start, Location end) {
int x0 = start.x, y0 = start.y; return generateBezierPath(start.x, start.y, end.x, end.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);
} }
/** /**

Loading…
Cancel
Save

Powered by TurnKey Linux.