Skip to content

Commit

Permalink
Merge pull request #66 from boholder/fix-windows-mouse-move-and-click
Browse files Browse the repository at this point in the history
Fix the failure that mouse click event is performed before mouse cursor moving event in Windows
  • Loading branch information
khanshoaib3 committed Jul 5, 2023
2 parents 8d7c4aa + 75044e6 commit 8495ea1
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 8495ea1

Please sign in to comment.