Search code examples
javatextboxmouseeventon-screen-keyboard

Java listener for mouse click on any textbox on the screen


Is there a way for Java to listen to another program for mouse clicks?

If so, is there a way to listen for mouse clicks on text inputs on other programs?

I'm making an on screen keyboard for a project I'm working on. It will automatically be displayed when the user selects any text input on the screen. When the text input is unfocused, the keyboard would disappear.


Solution

  • Strictly speaking, in Java there is no way to detect Mouse or Keyboard events when your application is not in focus. This is a security mechanism that is built into Java.

    An application cannot listen for these events unless it has root (admin) privileges anyway.