> I'm wondering how one could detect if a button (say a toolbar button)
> was clicked while the ctrl-key was held down. Is it possible to
> detect this modifier key in the actionPerformed() method of the
> action button itself?
I don't know (but other might) but if not, it should be possible
to add a KeyListener that gets this information independent from
the button being called. Setting an internal member in such a
case (and setting it back if the ctrl-key is released) should
allow you to "simulate" the modifier-information in actionPerformed.
Knowing if you speak of SWT, Swing or other GUI-frameworks
(e.g. GWT) might help answering that question as well ;-)
Regards, Lothar
--
Lothar Kimmeringer E-Mail: spam...@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
I did this once by using a KeyListener that toggled a class variable
when the CTRL key was pressed. Then in the ActionListener I checked the
value of the variable. I also remember there was somebody else at the
time that posted an even better solution but I can't remember what it
was. I have no clue what you could search for to find it though.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
>I'm wondering how one could detect if a button (say a toolbar button)
>was clicked while the ctrl-key was held down. Is it possible to
>detect this modifier key in the actionPerformed() method of the
>action button itself?
see http://mindprod.com/products2.html#KEYPLAYER
--
Roedy Green Canadian Mind Products
http://mindprod.com
If you think it�s expensive to hire a professional to do the job, wait until you hire an amateur.
~ Red Adair (born: 1915-06-18 died: 2004-08-07 at age: 89)
The actionPerformed() method is passed an ActionEvent instance;
its getModifiers() method will tell all.
--
Fred K
Yes. As Fred said (he replied to Roedy, so I'm replying to you just to
make sure you don't miss it), call getModifiers() inside
actionPerformed() to access the control key state:
actionEvent.getModifiers() & ActionEvent.CTRL_MASK
<http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html>
Come to think of it, that was probably the better solution :-).
--
Knute Johnson
email s/nospam/knute2010/