上传备份

wjdr
王兵 1 year ago
parent 4865efd9fb
commit 60ea0ac2d4

@ -9,18 +9,24 @@ import com.example.jmacro.wjdr.util.TaskUtil;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.concurrent.TimeUnit;
/**
* Java
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class JMacro {
public static void main(String[] args) throws AWTException {
JMacro jMacro = new JMacro();
jMacro.mouseMove(new ScreenPoint(100, 100));
jMacro.mouseLeftClick(new ScreenPoint(115, 614));
jMacro.keyInput(KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C, KeyEvent.VK_D, KeyEvent.VK_ENTER);
}
/**
@ -29,7 +35,26 @@ public class JMacro {
private final Robot robot;
public JMacro() throws AWTException {
// 机器人初始化
this.robot = new Robot();
this.robot.setAutoDelay(100);
}
/**
*
*/
public void keyInput(int... keycodes) {
for (int keycode : keycodes) {
keyPress(keycode);
}
}
/**
*
* keycode Key to press (e.g. <code>KeyEvent.VK_A)
*/
public void keyPress(int keycode) {
this.robot.keyPress(keycode);
}
/**
@ -51,7 +76,6 @@ public class JMacro {
if (smooth) {
// 获取当前鼠标位置
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
int startX = mousePoint.x;
int startY = mousePoint.y;
@ -60,13 +84,16 @@ public class JMacro {
double absY = Math.abs(startY - point.getY());
double absZ = Math.sqrt(Math.pow(absX, 2) + Math.pow(absY, 2));
int times = (int) (absZ / 30 + (absZ % 30 > 0 ? 1 : 0));
int interval = Math.min(500 / times, 10);
times = Math.min(times, 10);
// 分times次移动到指定点
for (int i = 1; i <= times; i++) {
float d = i * 1.0f / times;
int dx = (int) (startX + (point.getX() - startX) * d);
int dy = (int) (startY + (point.getY() - startY) * d);
robot.mouseMove(dx, dy);
robot.delay(RandomUtil.randomInt(5, 20));
robot.delay(RandomUtil.randomInt(interval - 10, interval + 10));
}
} else {
robot.mouseMove(point.getX(), point.getY());
@ -94,6 +121,60 @@ public class JMacro {
mouseLeftClick(new ScreenPoint(rect.getCenter()[0], rect.getCenter()[1]));
}
/**
*
*
* @param start
* @param end
*/
public void mouseLeftDrag(ScreenPoint start, ScreenPoint end) {
mouseLeftDrag(start, end, false);
}
/**
*
*
* @param start
* @param end
* @param smooth
*/
public void mouseLeftDrag(ScreenPoint start, ScreenPoint end, boolean smooth) {
mouseMove(start, smooth);
waitTap();
robot.mousePress(InputEvent.BUTTON1_MASK);
waitTap();
mouseMove(end, smooth);
waitTap();
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
/**
*
*
* @param start
* @param end
*/
public void mouseRightDrag(ScreenPoint start, ScreenPoint end) {
mouseRightDrag(start, end, false);
}
/**
*
*
* @param start
* @param end
* @param smooth
*/
public void mouseRightDrag(ScreenPoint start, ScreenPoint end, boolean smooth) {
mouseMove(start, smooth);
waitTap();
robot.mousePress(InputEvent.BUTTON3_MASK);
waitTap();
mouseMove(end, smooth);
waitTap();
robot.mouseRelease(InputEvent.BUTTON3_MASK);
}
/**
*
*

@ -2,6 +2,11 @@ package com.example.jmacro.wjdr;
/**
* 线
*
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public abstract class JMacroThread implements Runnable {

@ -16,6 +16,13 @@ import java.io.File;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* 线
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class MainTask {
/**
@ -80,19 +87,20 @@ public class MainTask {
public MacroThread(JMacro jMacro) {
super(jMacro);
// 定位mumu bar
Logger.info("定位慕慕窗口");
ScreenRect mumu = locationMuMu(jMacro);
if (mumu == null) {
throw new IllegalStateException("未检测到MuMu请开启MuMu模拟器");
}
Logger.info("线程启动成功");
Logger.info("定位慕慕窗口成功");
// 获取窗口返回
gameScreen = new ScreenRect();
gameScreen.setLeft(mumu.getLeft() - 428);
gameScreen.setTop(mumu.getTop() - 8);
gameScreen.setRight(mumu.getRight());
gameScreen.setBottom(mumu.getBottom() + 951);
Logger.info("窗口位置:" + gameScreen.toString());
Logger.info("窗口大小:{}x{}", gameScreen.getRight() - gameScreen.getLeft(), gameScreen.getBottom() - gameScreen.getTop());
Logger.info("应用窗口位置:" + gameScreen.toString());
Logger.info("应用窗口大小:{}x{}", gameScreen.getRight() - gameScreen.getLeft(), gameScreen.getBottom() - gameScreen.getTop());
}
@Override

Loading…
Cancel
Save

Powered by TurnKey Linux.