Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the failure that mouse click event is performed before mouse cursor moving event in Windows #66

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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