Catch Key When Not Focused
I'm writing a small program that needs to catch the escape key when there is no focus or window for that matter.
The program I have written uses a Robot to open up Notepad from the Start menu then starts typing "All work and no play makes Jack a dull boy. " for ever. I want it to stop typing when the escape key is hit.
Using a JTextField I've added a KeyListener using an inner class extending KeyAdapter. The text field has been set focusable but is not viewable on the screen.
The inner class never sees the escape key.
How do I get these events?
Another slant on this question would be how could I create a key logger, that is not my intention but I think the solution would be the same.

