Hi all,
I'm writing an UI that uses F1-F10 for its actions and have set up key
bindings for each of them. One particular action requires that the
immediately following input (F1-F10) do a new action in addition to
its regularly assigned action, but I'm having a devil of a time
figuring out how to do this. The most logical way it seemed would be
to (temporarily) assign multiple actions to each of the key bindings,
but it appears that InputMap & ActionMap's put() method overrides the
old binding instead of adding an _extra_ binding, which is what I
would have hoped would happen.
I then thought to assign the new action to all the keys which would in
the end rebind the keys to their old bindings and then manually run
the action associated with pressed key, but I can't figure out a way
to find out what the pressed key was! I thought to use ActionEvent's
getActionCommand() method, but that returns null for some reason. I
also thought to add a KeyListener which would add the pressed key to a
private variable, but doing so consumes all keyboard input such that
the actions associated with the bindings never happen at all!
Any help or ideas would be greatly appreciated.
Thank you,
Will
Will Friedman - 31 Mar 2004 08:58 GMT
Although I know it's very bad form to reply to one's own message, I
want to update my original post with some new information. I was able
to get key bindings to work with a KeyListener -- turns out that my
problem was setting the focus incorrectly. My two main questions
stand, which are:
Is there any way to assign multiple actions to a single key using key
bindings? (InputMap, ActionMap, etc.)?
Why does running getActionCommand() on the ActionEvent passed into an
action triggered by a key binding return null instead of either a
KeyEvent or KeyStroke?
Thanks,
Will