The program would need the focus to get the key press.
You would need JNI code for this app.