lmrlyv
lmrlyv

Reputation: 13

add LIstener on OS in JAVA

JFrame frame = new JFrame();
Robot bot = new Robot();
frame.addMouseListener(new MouseAdapter(){
  public void mouseClicked(MouseEvent e){
  bot.keyPress(KeyEvent.VK_SHIFT);
  bot.keyRelease(KeyEvent.VK_SHIFT);
}
});

I wrote program in Java when I click on JFrame, it will press SHIFT key automatically. But I don't want exactly this program. I want that when I click on Desktop or anywhere of O.S. (not only JFrame), it execute that command. Is there any way to do this? Please help me. Appreciate in advance

Upvotes: 1

Views: 102

Answers (1)

krishnakumarp
krishnakumarp

Reputation: 9295

You would need to use JNI to do this.

An approach to do this on Windows is given in this blog entry http://ksquared.de/blog/2011/07/java-global-system-hook/

Hope it helps.

Upvotes: 1

Related Questions