I’ve got a KeyboardFocusManager with overridden dispatchKeyEvent() method to handle navigation for arrow key and enter. I need to handle key events for as long as the key is pressed. Unfortunately, holding down enter results in KEY_TYPED events which do not contain the key location. Is there a way to find out which enter is currently being pressed? Or can I suppress KEY_TYPED events for enter in favour of KEY_PRESSED events?
edit:
I can’t tell you the reason why it’s done with a KeyboardFocusManager instead of KeyListeners but I’m sure there were reasons it was done this way. As of now, it is not possible anymore to change this. The problem is, that for our system(an old terminal emulator), the left enter key is a navigational key. Pressing enter moves the focus to the next textfield after the current line. The right enter key is a command key that sends the user input to the server.
Using the
KeyEventDemofound in How to Write a Key Listener, I am unable to reproduce the effect you describe for eitherKEY_PRESSEDorKEY_RELEASED. Of course, “KEY_TYPEDevents do not have akeyLocation.”It’s not clear why you are using a Focus Listener, as many components already bind certain keys to a defined
Action. The example binds the arrow keys, which respond to auto-repeat events regulated by the host’s preferences.