Skip to content

Commit

Permalink
change to use the system resolution instead of fixed resolution(100x100)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuitty committed May 2, 2023
1 parent 565fc40 commit d6bbc2c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/com/test/MyThread.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.test;

import java.awt.AWTException;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.MouseInfo;
import java.awt.Robot;

Expand All @@ -18,6 +20,9 @@ public MyThread(Long time) {

@Override
public void run() {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int maxWidth = gd.getDisplayMode().getWidth();
int maxHeight = gd.getDisplayMode().getHeight();
Robot robot = null;
try {
robot = new Robot();
Expand All @@ -32,8 +37,8 @@ public void run() {
int x1 = MouseInfo.getPointerInfo().getLocation().x;
int y1 = MouseInfo.getPointerInfo().getLocation().y;
if (x == x1 && y == y1) {
robot.mouseMove((int) Math.round(Math.random() * 100 + 0.1D),
(int) Math.round(Math.random() * 100 + 0.1D));
robot.mouseMove((int) Math.floor(Math.random() * maxWidth) + 1,
(int) Math.floor(Math.random() * maxHeight) + 1);
x1 = MouseInfo.getPointerInfo().getLocation().x;
y1 = MouseInfo.getPointerInfo().getLocation().y;
System.out.println(++times);
Expand Down

0 comments on commit d6bbc2c

Please sign in to comment.