Help with accepting input from another focused window using Java
I want to write a program that responds when I press a certain key on the keyboard. However, there will be a completely unrelated full-screen program running in the foreground and my program won't have the window focus.
So, basically, what I want to do is start my program and have it run in the background, then start the full-screen program. And then I want to be able to get my prog开发者_如何学JAVAram to do stuff in the background when I press a certain key.
Is there a way to do this in Java? If not, is there any way at all to do it?
My platform is Windows 7.
A keystroke is an O/S event. You can write a listener in C++ using hooks, then create a JNI interface on top of it.
Lookup MSDN entry for "SetWindowsHookEx" function for hooking procedure.
If you don't want to fuss with JNI, consider implementing the listener in Visual C++ or Visual Basic and cross-compiling the .NET binaries into Java bytecode. Here is a free tool to do that: http://www.ikvm.net/
精彩评论