Is there a KeyPreview equivalent in Java?
Posted on 2014-10-23
In other languages (.NET, Delphi, etc.) there's a KeyPreview option where you can flag it so that you can capture KeyPress events regardless of which component they take place in. I can't seem to find an equivalent in Java.
I know that there's a swing KeyStroke object you can use to "bind" individual "actions" to a specific method, but this is definitely not what I'm looking for.
So far, the only options I can see is either:
1.) Overlaying an invisible object over the entire window, then manually handling all key events, focus, etc. in all objects (horrible).
2.) Add a static custom KeyInputListener to every single component in the application. (Almost as horrible as 1, but not quite.)
3.) Create a KeyStroke "bind" for every conceivable keypress on every conceivable keyboard type. Impossible.
Hoping for something much cleaner.