Reputation: 2222
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.
Upvotes: 3
Views: 142
Reputation: 205785
Using the KeyEventDemo
found in How to Write a Key Listener, I am unable to reproduce the effect you describe for either KEY_PRESSED
or KEY_RELEASED
. Of course, "KEY_TYPED
events do not have a keyLocation
."
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.
Upvotes: 3