Currently stuck on how to create an executable jar file that would run in the background of my pc and detect if my mouse is down. I know JFrame is a one method of doing so, but that's visible on my screen, even though I set it to invisible it appears to disable it completely.
Here's my code so far, is there a another method I could use that isn't JFrame related?
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);
}
}
}
You can download jNativeHook
and hook the global listener to globalScreen
.
you can use it as a normal swing listener.
Here is the link:
https://code.google.com/p/jnativehook/
By using this library you achieve a wide range of functions to control the mouse events!!