So, I want to trigger an event (pause / pause some media) whenever a user presses a space anywhere in my Swing application.
Since there are so many controls and panels that could focus, it is actually impossible to add all the key events to them (not to mention gross).
So i found
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher()
which is awesome, you can register global keystroke pre-handlers. There is a big problem: spaces will be entered all the time in input fields, table cells, etc., And I obviously do not want to trigger a pause event then!
So any ideas? Perhaps there is a way to detect globally whether the cursor is focused on what allows you to enter text without having to check the list of all editable controls (vomit!)?
source
share