目前停留在如何创建一个可执行的 jar 文件,该文件将在我的电脑后台运行并检测我的鼠标是否已关闭。我知道 JFrame 是这样做的一种方法,但这在我的屏幕上是可见的,即使我将它设置为不可见,它似乎完全禁用它。
到目前为止,这是我的代码,是否有另一种与 JFrame 无关的方法可以使用?
public class MyFrame extends JFrame implements KeyListener {
MyFrame(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500,500);
this.setLayout(null);
this.addKeyListener(this);
this.setVisible(true);
this.setAlwaysOnTop(true);
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
if(e.getKeyChar() =='q'){
this.setVisible(false);
}
if(e.getKeyChar()=='l'){
this.setVisible(true);
}
}
}
您可以下载jNativeHook
全局侦听器并将其挂接到globalScreen
.
您可以将其用作普通的摇摆监听器。
链接在这里:
https://code.google.com/p/jnativehook/
通过使用这个库,您可以实现多种功能来控制鼠标事件!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句