Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Can't catch CTRL-C if the user releases the keys in the wrong order.
Can't catch CTRL-C if the user releases the keys in the wrong order. [message #869688] Thu, 03 May 2012 16:36 Go to next message
Eclipse UserFriend
We have an application using SWT widgets. We'd like to do some processing when a user clicks CTRL-C when one of the widgets has focus. We added a KeyListener to the object, and in the keyReleased() method we checked for CTRL-C this way:
if ((ev.stateMask == 0x40000) && (ev.keyCode == 67))
. Depending on the order the user released the keys, the stateMask is either 0 or has the value for CTRL. If the user released the CTRL key first, the stateMask is 0; if the user released the C key first, the stateMask has the value for CTRL. So sometimes our code gets processed, and sometimes it doesn't. Is that what should happen? Is there anyway to process this as CTRL-C regardless of which key is released first? Thanks.
Re: Can't catch CTRL-C if the user releases the keys in the wrong order. [message #870515 is a reply to message #869688] Tue, 08 May 2012 09:52 Go to previous messageGo to next message
Eclipse UserFriend
Listeners like this are usually hooked on KeyPressed rather than
KeyReleased. If you change to this then you'll likely find that users
won't make the mistake you're describing, as I can't imagine going to
press Ctrl+C and pressing the 'C' first.

Grant


On 5/3/2012 4:36 PM, Dave Dell wrote:
> We have an application using SWT widgets. We'd like to do some
> processing when a user clicks CTRL-C when one of the widgets has focus.
> We added a KeyListener to the object, and in the keyReleased() method we
> checked for CTRL-C this way: if ((ev.stateMask == 0x40000) &&
> (ev.keyCode == 67)). Depending on the order the user released the keys,
> the stateMask is either 0 or has the value for CTRL. If the user
> released the CTRL key first, the stateMask is 0; if the user released
> the C key first, the stateMask has the value for CTRL. So sometimes our
> code gets processed, and sometimes it doesn't. Is that what should
> happen? Is there anyway to process this as CTRL-C regardless of which
> key is released first? Thanks.
Re: Can't catch CTRL-C if the user releases the keys in the wrong order. [message #870568 is a reply to message #870515] Tue, 08 May 2012 15:01 Go to previous message
Eclipse UserFriend
Well, interestingly enough, today I just tried to catch it using keyPressed(), but it didn't work. What I discovered is that if you have the CTRL key pressed, the keyPressed() method never gets called, even when pressing the "c". I also learned that the Windows OS doesn't copy to the clipboard if you press "c" and then CTRL. So what I did was set a flag in keyPressed() when called to indicate that an invalid copy key sequence was pressed, because the only time it will get called is when a key is pressed by itself (not with a CTRL key). I then checked that flag in the keyReleased() method. If the flag hadn't been set by keyPressed() and the key pressed was a "c" then I assumed the user just released CTRL-C (in any order) and do the processing that needs to be done in that case.
Previous Topic:XULRUNNER set profile
Next Topic:Problem forcing focus in combo text field
Goto Forum:
  


Current Time: Sun Aug 31 08:51:04 EDT 2025

Powered by FUDForum. Page generated in 0.03329 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top