im still pretty new to Java but im having this issue when trying to detect if my mouse is down. I saw a another post about this issue, but the answer didn't seem to work for me. Here's the code, simply trying to make it only click when the mouse is down.
@Override
public void nativeMousePressed(NativeMouseEvent nativeMouseEvent) {
if (nativeMouseEvent.getButton() == NativeMouseEvent.BUTTON1 && BUTTON1 == 1) {
Robot robot;
try {
robot = new Robot();
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
robot.delay(50);
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
Take a look at jwinkey It looks something like this and works without any Swing or FX Component open or in focus:
var observable = KeyStateObservable.of(VirtualKey.VK_LEFT_MOUSE_BUTTON);
observable.subscribe((event) -> {
System.out.println(event.getVirtualKeyCode());
});
But you need to add io.reactivex.rxjava3 for Obserable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.