0

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?

3
  • 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. Commented Sep 19, 2010 at 21:37
  • Possible duplicates: stackoverflow.com/questions/901224/…, stackoverflow.com/questions/800747/… Commented Sep 20, 2010 at 5:54
  • @camickr, JNA might be easier to deal with, most of the Windows APIs already have C interfaces... Commented Sep 30, 2010 at 1:51

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Simply put, the only way it can be done is with JNI.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.