Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Is there a way to actively "read" keyboard modifier state?
Is there a way to actively "read" keyboard modifier state? [message #451612] Thu, 03 March 2005 11:45 Go to next message
sergey is currently offline sergeyFriend
Messages: 6
Registered: July 2009
Junior Member
I am implementing a toolbar that should do different things depending on
keyboard modifier state, for example, clicking on a toolbar button when
SHIFT is pressed, and when it is not, would have different effects.

One possible solution would be to listen for key and mouse events for
the toolbar control and preserve modifier state, so the latest state
would be available in Selection event listener for the toolbar button.
Listening for mouse events is important, since a modifier might have
been pressed down when keyboard focus belonged to a different control,
so listening for mouse events would capture the current state if
selection is made with mouse.

Another option would be to have a Display filter listening for key
events, and again, preserving current modifier state somewhere in a
global application state.

My question is whether there is a way to actively "read" current
keyboard state vs. listening for events? This would allow in the
scenario above, on toolbar button Selection event, to "read" the current
modifier state and modify behavior appropriately without resorting to
low-level event tracking. I did check the API, but could not find a way
to do this.

Is there a better way to implement the desired behavior?

Thanks,
Sergey
Re: Is there a way to actively "read" keyboard modifier state? [message #451617 is a reply to message #451612] Thu, 03 March 2005 12:27 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
The mouse event contains the keyboard state:

/**
* the state of the keyboard modifier keys at the time
* the event was generated
*/
public int stateMask;

Also, the selection event contains the keyboard event (statemask).

Note, it is better to use the selection event than the mouse event because
it is more accessible and more consistent with the paltform behvaiour.

"sergey" <sergey@xxxxxxxxx.com> wrote in message
news:d06tcv$fq4$1@www.eclipse.org...
>I am implementing a toolbar that should do different things depending on
>keyboard modifier state, for example, clicking on a toolbar button when
>SHIFT is pressed, and when it is not, would have different effects.
>
> One possible solution would be to listen for key and mouse events for the
> toolbar control and preserve modifier state, so the latest state would be
> available in Selection event listener for the toolbar button. Listening
> for mouse events is important, since a modifier might have been pressed
> down when keyboard focus belonged to a different control, so listening for
> mouse events would capture the current state if selection is made with
> mouse.
>
> Another option would be to have a Display filter listening for key events,
> and again, preserving current modifier state somewhere in a global
> application state.
>
> My question is whether there is a way to actively "read" current keyboard
> state vs. listening for events? This would allow in the scenario above,
> on toolbar button Selection event, to "read" the current modifier state
> and modify behavior appropriately without resorting to low-level event
> tracking. I did check the API, but could not find a way to do this.
>
> Is there a better way to implement the desired behavior?
>
> Thanks,
> Sergey
Re: Is there a way to actively "read" keyboard modifier state? [message #451642 is a reply to message #451617] Thu, 03 March 2005 23:05 Go to previous message
sergey is currently offline sergeyFriend
Messages: 6
Registered: July 2009
Junior Member
Thanks Veronika.

I understand that key and mouse events have statemask. That's the basis
for implementation options 1) and 2) below.

I was wondering about option 3) - if there is a way to _read_ keyboard
state actively, as opposed to listening to events.

BTW, I don't think that statemask is populated for selection events.

Thanks again,
Sergey


Veronika Irvine wrote:
> The mouse event contains the keyboard state:
>
> /**
> * the state of the keyboard modifier keys at the time
> * the event was generated
> */
> public int stateMask;
>
> Also, the selection event contains the keyboard event (statemask).
>
> Note, it is better to use the selection event than the mouse event because
> it is more accessible and more consistent with the paltform behvaiour.
>
> "sergey" <sergey@xxxxxxxxx.com> wrote in message
> news:d06tcv$fq4$1@www.eclipse.org...
>
>>I am implementing a toolbar that should do different things depending on
>>keyboard modifier state, for example, clicking on a toolbar button when
>>SHIFT is pressed, and when it is not, would have different effects.
>>
>>One possible solution would be to listen for key and mouse events for the
>>toolbar control and preserve modifier state, so the latest state would be
>>available in Selection event listener for the toolbar button. Listening
>>for mouse events is important, since a modifier might have been pressed
>>down when keyboard focus belonged to a different control, so listening for
>>mouse events would capture the current state if selection is made with
>>mouse.
>>
>>Another option would be to have a Display filter listening for key events,
>>and again, preserving current modifier state somewhere in a global
>>application state.
>>
>>My question is whether there is a way to actively "read" current keyboard
>>state vs. listening for events? This would allow in the scenario above,
>>on toolbar button Selection event, to "read" the current modifier state
>>and modify behavior appropriately without resorting to low-level event
>>tracking. I did check the API, but could not find a way to do this.
>>
>>Is there a better way to implement the desired behavior?
>>
>>Thanks,
>>Sergey
>
>
>
Previous Topic:Multi-line Text with constant number of visible rows...
Next Topic:about swt 's thread .
Goto Forum:
  


Current Time: Thu Apr 25 11:53:34 GMT 2024

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

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

Back to the top