If your java program does not have focus I don't know that you can have it recognize keystrokes being given to another program. That sounds like an OS feature.