Skip to content

Commit

Permalink
Fix the failure that mouse click event is performed before mouse curs…
Browse files Browse the repository at this point in the history
…or moving event in Windows, close #65
  • Loading branch information
boholder committed Jul 2, 2023
1 parent 8d7c4aa commit 75044e6
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

/**
* Contains functions to simulate mouse events.
Expand All @@ -21,6 +22,15 @@ public class MouseUtils {
*/
public static void moveAndLeftClick(int x, int y) {
move(x, y);
// fix the https://github.com/khanshoaib3/minecraft-access/issues/65
if (OsUtils.isWindows()) {
try {
// with a little bit of waiting, everything is ok now.
// I've tried to set the value to 10, and it doesn't always work, 20 is fine.
TimeUnit.MILLISECONDS.sleep(20);
} catch (Exception ignored) {
}
}
leftClick();
}

Expand All @@ -31,6 +41,12 @@ public static void moveAndLeftClick(int x, int y) {
*/
public static void moveAndRightClick(int x, int y) {
move(x, y);
if (OsUtils.isWindows()) {
try {
TimeUnit.MILLISECONDS.sleep(20);
} catch (Exception ignored) {
}
}
rightClick();
}

Expand Down

0 comments on commit 75044e6

Please sign in to comment.