0

What is wrong is when I set the variable isleftmousedown to true it will test it twice when it is tested in a while loop because I tested it with a while loop and you can see this below! If it helps you I am using JNativeHook with this project!

public static NativeMousePressed(NativeMouseEvent e) {
    isleftmousedown = true;
}

public static NativeMouseReleased(NativeMouseEvent e) {
    isleftmousedown = false;
}

This is the loop:

while (true) {
    try {
        Thread.sleep(1);

        if (isleftmousedown) {
            System.out.println("test");
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
  • It could be because loop is running faster than the key listener can mutate the values. Or chances are, the key listener is handled on a separate thread, and you have no memory barriers in place, allowing for data races. – Vince Jan 30 '18 at 15:45
  • I tested it other classes and things can run at the same time as this while loop! – ElementCodez Jan 30 '18 at 17:35
  • Please do not know to fix i dont think that is the problem! – ElementCodez Feb 01 '18 at 00:23

0 Answers0