I want to perform a specific action anytime a certain key combination is pressed while the program is running even if the window is not in focus. For instance, if I press CTRL-U the program would exit. Is this possible?
Asked
Active
Viewed 149 times
0
-
This is not supported by Java. Java can only respond to KeyEvents when a window is in focus. You need to use JNI (which I know nothing about) or another language that does allow access to the OS. – camickr Sep 19 '10 at 21:37
-
Possible duplicates: http://stackoverflow.com/questions/901224/listening-for-input-without-focus-in-java, http://stackoverflow.com/questions/800747/event-listener-in-java-without-app-having-focus-global-keypress-detection – Ash Sep 20 '10 at 05:54
-
@camickr, JNA might be easier to deal with, most of the Windows APIs already have C interfaces... – Mark Elliot Sep 30 '10 at 01:51
2 Answers
0
Your only real option for this is a lot of JNI. However, this can be quite cumbersome and hard to achieve. My advice is to either go straight C/C++ or not attempt this.

user478160
- 16
- 3