上传备份

master
王兵 1 week ago
parent 04961abb42
commit 5cce2364ef

@ -187,7 +187,7 @@ public abstract class JMacro {
* @param region * @param region
*/ */
public void mouseMove(Region region) { public void mouseMove(Region region) {
mouseMove(randomCenter(region)); mouseMove(rand(region));
} }
/** /**
@ -203,7 +203,7 @@ public abstract class JMacro {
* @param region * @param region
*/ */
public void mouseLeftClick(Region region) { public void mouseLeftClick(Region region) {
mouseMove(randomCenter(region)); mouseMove(rand(region));
mouseLeftClick(); mouseLeftClick();
} }
@ -228,7 +228,7 @@ public abstract class JMacro {
* *
*/ */
public void mouseLeftDoubleClick(Region region) { public void mouseLeftDoubleClick(Region region) {
mouseMove(randomCenter(region)); mouseMove(rand(region));
mouseLeftDoubleClick(); mouseLeftDoubleClick();
} }
@ -253,7 +253,7 @@ public abstract class JMacro {
* @param region * @param region
*/ */
public void mouseRightClick(Region region) { public void mouseRightClick(Region region) {
mouseMove(randomCenter(region)); mouseMove(rand(region));
mouseRightClick(); mouseRightClick();
} }
@ -556,40 +556,51 @@ public abstract class JMacro {
return legends; return legends;
} }
/** /**
* * @param location
* * @param radius
* @param region * @return
* @return
*/ */
public Location randomCenter(Region region) { public Location rand(Location location, int radius) {
int x1 = Mouse.at().getX(); int x1 = Mouse.at().getX();
int y1 = Mouse.at().getY(); 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 lx = location.getX();
int cy = center.getY(); int ly = location.getY();
// 判断鼠标是否在区域中心以内 // 判断鼠标是否在区域中心以内
if (x1 >= cx - radius && x1 <= cx + radius && y1 >= cy - radius && y1 <= cy + radius) { if (x1 >= lx - radius && x1 <= lx + radius && y1 >= ly - radius && y1 <= ly + radius) {
return Mouse.at(); return Mouse.at();
} }
int x = center.getX() + RandomUtil.randomInt(-radius, radius); int x = location.getX() + RandomUtil.randomInt(-radius, radius);
int y = center.getY() + RandomUtil.randomInt(-radius, radius); int y = location.getY() + RandomUtil.randomInt(-radius, radius);
return new Location(x, y); return new Location(x, y);
} }
/**
* @param x x
* @param y y
* @param radius
* @return
*/
public Location rand(int x, int y, int radius) {
return rand(new Location(x, y), radius);
}
/**
*
*
* @param region
* @return
*/
public Location rand(Region region) {
// 得到区域中心随机半径
int radius = (int) (Math.min(region.getW(), region.getH()) / 2 * 0.9f);
return rand(region.getCenter(), radius);
}
/** /**
* *
* *

Loading…
Cancel
Save

Powered by TurnKey Linux.