I am making a autoclicker in java for fun and keep having this issue where JNativeHook and JNA think the mouse is held down when its not, I know this is from the Robot Method causing it to change, I was wondering if there was anyway to check if the real mouse from the system is held down where the robot can't mess with it or if there is a way to send clicks without triggering pressed down events.
if any other code is need let me know thanks for any help!
//MouseHook.isMouseDown is getting if the mouse is down using JNA.
//canContinue is if their inside a set Window
if (mouseHoldDetector.leftClicked
&& MouseHook.isMouseDown
&& canContinue && toggleButton.isSelected()) {
long now = System.currentTimeMillis();
//some randomization
if (nextLDown > 0L && nextLUp > 0L) {
if (now > nextLDown) {
//send release first as the mouse is down.
robot.mouseRelease(16);
Thread.sleep(2L);
robot.mousePress(16);
if (jitterButton.isSelected()) {
robot.mouseMove(MouseInfo.getPointerInfo().getLocation().x + (int) setRandom(-10, 10),
MouseInfo.getPointerInfo().getLocation().y + (int) setRandom(-10, 5));
}
randomiseLeft();
}
} else {
randomiseLeft();
}
} else {
nextLUp = nextLDown = 0L;
}
@Override
public void nativeMousePressed(NativeMouseEvent e) {
// detect if left mouse button is held down
if (e.getButton() == NativeMouseEvent.BUTTON1) {
this.leftClicked = true;
}
}
@Override
public void nativeMouseReleased(NativeMouseEvent e) {
// not used in this example
if (e.getButton() == NativeMouseEvent.BUTTON1) {
this.leftClicked = false;
}
}
}
I tried using JNA to see if that would help, and still got the same result, jnativehook says pressed down when autoclicking when my mouse isn't down as well. I've tried putting the thread to higher sleep times, adding a delay before clicking, and checking if they right clicked, none seemed to help.