[英]java natative hook mouse event detecting issue
im still pretty new to Java but im having this issue when trying to detect if my mouse is down.我对 Java 还是很陌生,但是在尝试检测我的鼠标是否关闭时遇到了这个问题。 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:看看jwinkey它看起来像这样,并且在没有任何 Swing 或 FX 组件打开或聚焦的情况下工作:
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
但是你需要为 Obserable 添加Obserable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.