I have a Swing app that needs to display different sets of controls based on whether the control or alt keys are pressed. I added a KeyListener to the main component, but i
You may want to try to use key binding rather than KeyListeners. Key binding is a higher level construct and can listen for key presses even if the component that "listens" doesn't have the focus -- as opposed to KeyListeners. You can find more on these at the Swing tutorials: How to use key bindings