Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Events not passed up to Shell?
Events not passed up to Shell? [message #453876] Wed, 13 April 2005 15:29 Go to next message
No real name is currently offline No real nameFriend
Messages: 32
Registered: July 2009
Member
I have a simple Shell with a few widgets on it. I'd like to add a
KeyListener to the shell to intercept all keyboard events, regardless of
whether any particular widget has focus.

Unfortunately, this doesn't seem to be working. Adding a listener to a
widget works fine, of course, but if a widget has focus and does not
have a listener then the Shell listener does not get the event...

Is there any way to make this work? Attaching a duplicate listener to
each widget just to handle a particular keystroke seems a little
stupid....



- bill
--
bill@hutten.org
Re: Events not passed up to Shell? [message #453912 is a reply to message #453876] Wed, 13 April 2005 18:07 Go to previous messageGo to next message
Emil Crumhorn is currently offline Emil CrumhornFriend
Messages: 169
Registered: July 2009
Senior Member
Add the keylistener to the Display as a filter. Here's how (can change out
Display.getDefault() to your display if you want):

Display.getDefault().display.addFilter(SWT.KeyDown, new Listener() {
public void handleEvent(Event event) {
// do your thing
}
}

This will fire for any sub-shell as well, if you have multiple shells and
only want a particular shell, just see what shell is being fired by fetching
getActiveShell() from the display object to see what shell is which.

Emil


"Bill Hutten" <bill@hutten.org> wrote in message
news:bill-877B28.12291313042005@news.eclipse.org...
>
> I have a simple Shell with a few widgets on it. I'd like to add a
> KeyListener to the shell to intercept all keyboard events, regardless of
> whether any particular widget has focus.
>
> Unfortunately, this doesn't seem to be working. Adding a listener to a
> widget works fine, of course, but if a widget has focus and does not
> have a listener then the Shell listener does not get the event...
>
> Is there any way to make this work? Attaching a duplicate listener to
> each widget just to handle a particular keystroke seems a little
> stupid....
>
>
>
> - bill
> --
> bill@hutten.org
Re: Events not passed up to Shell? [message #453913 is a reply to message #453912] Wed, 13 April 2005 18:08 Go to previous messageGo to next message
Emil Crumhorn is currently offline Emil CrumhornFriend
Messages: 169
Registered: July 2009
Senior Member
Wops, got too much code in there, here's the right one. Typed it from
keyboard =p

Display.getDefault().addFilter(SWT.KeyDown, new Listener() {
public void handleEvent(Event event) {
// do your thing
}
}

"Emil Crumhorn" <crumhorn@speakeasy.net> wrote in message
news:d3jngg$om6$1@news.eclipse.org...
> Add the keylistener to the Display as a filter. Here's how (can change out
> Display.getDefault() to your display if you want):
>
> Display.getDefault().display.addFilter(SWT.KeyDown, new Listener() {
> public void handleEvent(Event event) {
> // do your thing
> }
> }
>
> This will fire for any sub-shell as well, if you have multiple shells and
> only want a particular shell, just see what shell is being fired by
> fetching getActiveShell() from the display object to see what shell is
> which.
>
> Emil
>
>
> "Bill Hutten" <bill@hutten.org> wrote in message
> news:bill-877B28.12291313042005@news.eclipse.org...
>>
>> I have a simple Shell with a few widgets on it. I'd like to add a
>> KeyListener to the shell to intercept all keyboard events, regardless of
>> whether any particular widget has focus.
>>
>> Unfortunately, this doesn't seem to be working. Adding a listener to a
>> widget works fine, of course, but if a widget has focus and does not
>> have a listener then the Shell listener does not get the event...
>>
>> Is there any way to make this work? Attaching a duplicate listener to
>> each widget just to handle a particular keystroke seems a little
>> stupid....
>>
>>
>>
>> - bill
>> --
>> bill@hutten.org
>
>
Re: Events not passed up to Shell? [message #453917 is a reply to message #453913] Wed, 13 April 2005 21:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

The filter gets called first, before any component gets to see the key?

Bob Foster

Emil Crumhorn wrote:
> Wops, got too much code in there, here's the right one. Typed it from
> keyboard =p
>
> Display.getDefault().addFilter(SWT.KeyDown, new Listener() {
> public void handleEvent(Event event) {
> // do your thing
> }
> }
>
> "Emil Crumhorn" <crumhorn@speakeasy.net> wrote in message
> news:d3jngg$om6$1@news.eclipse.org...
>
>>Add the keylistener to the Display as a filter. Here's how (can change out
>>Display.getDefault() to your display if you want):
>>
>>Display.getDefault().display.addFilter(SWT.KeyDown, new Listener() {
>> public void handleEvent(Event event) {
>> // do your thing
>> }
>>}
>>
>>This will fire for any sub-shell as well, if you have multiple shells and
>>only want a particular shell, just see what shell is being fired by
>>fetching getActiveShell() from the display object to see what shell is
>>which.
>>
>>Emil
>>
>>
>>"Bill Hutten" <bill@hutten.org> wrote in message
>>news:bill-877B28.12291313042005@news.eclipse.org...
>>
>>>I have a simple Shell with a few widgets on it. I'd like to add a
>>>KeyListener to the shell to intercept all keyboard events, regardless of
>>>whether any particular widget has focus.
>>>
>>>Unfortunately, this doesn't seem to be working. Adding a listener to a
>>>widget works fine, of course, but if a widget has focus and does not
>>>have a listener then the Shell listener does not get the event...
>>>
>>>Is there any way to make this work? Attaching a duplicate listener to
>>>each widget just to handle a particular keystroke seems a little
>>>stupid....
>>>
>>>
>>>
>>>- bill
>>>--
>>>bill@hutten.org
>>
>>
>
>
Re: Events not passed up to Shell? [message #453923 is a reply to message #453876] Wed, 13 April 2005 23:21 Go to previous messageGo to next message
Joern Ihlenburg is currently offline Joern IhlenburgFriend
Messages: 1
Registered: July 2009
Junior Member
Hi Bill,

the problöem is that the OS won't pass the events to the shell. Only the
widget owning the focus will get the key events...

Joern

Bill Hutten schrieb:
> I have a simple Shell with a few widgets on it. I'd like to add a
> KeyListener to the shell to intercept all keyboard events, regardless of
> whether any particular widget has focus.
>
> Unfortunately, this doesn't seem to be working. Adding a listener to a
> widget works fine, of course, but if a widget has focus and does not
> have a listener then the Shell listener does not get the event...
>
> Is there any way to make this work? Attaching a duplicate listener to
> each widget just to handle a particular keystroke seems a little
> stupid....
>
>
>
> - bill
Re: Events not passed up to Shell? [message #997170 is a reply to message #453923] Fri, 04 January 2013 09:07 Go to previous message
Suryakant Bhagat is currently offline Suryakant BhagatFriend
Messages: 2
Registered: January 2013
Junior Member
Thans for the solution. I was also struggling to add some key events to the display directly instead of individual views and it worked wonderfully.
Previous Topic: Eclipse mouse right-click issue with X11 forwarding
Next Topic:Manually creating and firing events from inside another listener
Goto Forum:
  


Current Time: Sun Nov 23 07:45:54 GMT 2014

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

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