昨天,做了怎么获取x,y的地址,今天就做输入地址,鼠标“啪”一下闪现过去点他一下,话不多说上代码。
public class Click {
static double x ;
static double y ;
public static void main(String[] args) {
Robot robot = null;
Scanner scanner = new Scanner(System.in);
x = scanner.nextDouble();
y = scanner.nextDouble();
System.out.println(x + "\t" + y);
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
robot.mouseMove((int) x, (int) y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
}
做到这里,想在给用户一个确认的机会
中间加个判断吧
后面想了想,判断错了还要重新来,还是加个循环吧
public class Click2 {
static int a=0;
static double x ;
static double y ;
public static void main(String[] args) {
while (a==0){
Robot robot = null;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入鼠标X坐标");
x = scanner.nextDouble();
System.out.println("请输入鼠标Y坐标");
y = scanner.nextDouble();
System.out.println(x + "\t" + y);
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
robot.mouseMove((int) x, (int) y);
System.out.println("是否是该位置,不是请输入0,是请输入非零数");
a= scanner.nextInt();
if (a == 1 ) {
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}else {
System.out.println("请重新输入");
}
}
}
}
ok 第二天到此为止
关注我那八个小粉丝,你们是我前进的动力,出乎意料呀。哈哈哈