Generally we apply the Key Listener on specific components like text field, password fields, etc. But I would like to generalize this listener behavior to be applicable to all.
Swing was designed to be used with Key Bindings which might do what you want. I would start by checking out Key Bindings. Don't forget to read the Swing tutorial for complete information.
If that doesn't help then see Global Event Listeners for a couple of suggestions.
2.1m questions
2.1m answers
60 comments
57.0k users