Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java, How to detect keypresses without using GUI components?

Using Java, is it possible to detect user actions, such as key-presses, mouse-button-presses, and/or mouse's screen location, without the use of GUI elements?

If it is, how could I implement it?

Otherwise, what are the alternatives?


The only StackOverflow source i found on this matter is this question, which is unanswered.

And the only sources I found outside StackOverflow on this matter point to an "Invisible GUI" solution, wish is something i really want to avoid.

like image 741
XenoRo Avatar asked Nov 13 '22 01:11

XenoRo


1 Answers

It can be implemented using JNI and/or JNA but this cannot be really called "java implementation" because you will have to write platform specific native code.

Alternative solution I tried is to use full screen transparent widow that is listening to all events of mouse and keyboard and "forwards" them to the real application using class Robot. I tried this approach. It works well with one limitation: there is a problem to support "mouse over" events of applications: the mouse is not moving over the real application. It is moving over the transparent java window.

like image 50
AlexR Avatar answered Dec 21 '22 05:12

AlexR