Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Posting event from linux doesn't work like with windows(How to fire a heypressed event with linux)
Posting event from linux doesn't work like with windows [message #1716211] Wed, 02 December 2015 09:05 Go to next message
Nicolas DI POL is currently offline Nicolas DI POLFriend
Messages: 9
Registered: December 2015
Junior Member
Hello everyone

I'm new in the java world but not new in programming

I'm really dispointed about the difference between linux and windows for handling events

I know that SWT is a single UI thread but I try to post event from another shell (like virtual keyboard) to my widgets and it only works 1 of 10 times.

from the shell I use as virtual keyboard I send events like this :

Event MyEvent = new Event();
MyEvent.type = SWT.KeyDown;
MyEvent.character = text.getText().charAt(0);
MyBrowser.setFocus();
Display.getCurrent().post(MyEvent);
MyEvent.type = SWT.KeyUp;
MyBrowser.getDisplay().post(MyEvent);

this is working pretty nice with Windows but huuuuuu linux doesn't seems to fire the event into MyBrowser

I really face a wall since days and I haven't found a solution for now. I wonder if I'm allone to face this problem or it's to obvious to post it into a forum Smile

Thanks for your help

Nicolas

Re: Posting event from linux doesn't work like with windows [message #1716277 is a reply to message #1716211] Wed, 02 December 2015 16:19 Go to previous messageGo to next message
Eclipse UserFriend
When using Display#post(), you need to inject both SWT.KeyDown AND SWT.KeyUp events. In my experience, you also need to provide keyCode values, not just the character. Modifiers (e.g., Alt, Ctrl, Shift) need to also be toggled on and then off with SWT.KeyDown/KeyUp events. I'm not entirely sure that the Browser widgets can be posted to.
Re: Posting event from linux doesn't work like with windows [message #1716291 is a reply to message #1716277] Wed, 02 December 2015 17:35 Go to previous messageGo to next message
Nicolas DI POL is currently offline Nicolas DI POLFriend
Messages: 9
Registered: December 2015
Junior Member
Hello Brian and thanks for your reply

I have some interogations because :

1) With a Windows platform it works
2) my little example in my post works if I use a button in the same shell than my widget

Does Linux handle event in another way? from my point of view the event loop isn't informed from my display.post

I don't see how to post the keyDown and KeyUp in the same post, maybe you have an example?

thanks for your help

Nicolas
Re: Posting event from linux doesn't work like with windows [message #1716292 is a reply to message #1716291] Wed, 02 December 2015 17:46 Go to previous messageGo to next message
Eclipse UserFriend
You have to perform two post events, the first for SWT.KeyDown, and the next for SWT.KeyUp. There are a number of uses of Display.post() within the Eclipse Platform, including our unit tests which run on Linux, so it does work.
Re: Posting event from linux doesn't work like with windows [message #1716338 is a reply to message #1716292] Thu, 03 December 2015 06:24 Go to previous messageGo to next message
Nicolas DI POL is currently offline Nicolas DI POLFriend
Messages: 9
Registered: December 2015
Junior Member
Hzllo Brian

thanks again for your help

I effectivily send two posts event, one with KeyDown, one with KeyUp

look....if I use that code in the same shell than the widget it works


public void KeyboardEvent(Browser TheBrowser, Event Theevent){
TheBrowser.setFocus();
TheBrowser.getDisplay().post(Theevent);
System.out.println("KeyEvent"+Theevent);
}

Button btnZoom_1 = new Button(compositeButtons, SWT.NONE);
btnZoom_1.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
Event MyEvent = new Event();
MyEvent.type = SWT.KeyDown;
MyEvent.keyCode = 0x40000;
KeyboardEvent(MyBrowser,MyEvent);
MyEvent.type = SWT.KeyDown;
MyEvent.keyCode = 0x100002d;
KeyboardEvent(MyBrowser,MyEvent);
MyEvent.type = SWT.KeyUp;
KeyboardEvent(MyBrowser,MyEvent);
MyEvent.type = SWT.KeyUp;
MyEvent.keyCode = 0x40000;
KeyboardEvent(MyBrowser,MyEvent);
}
});
btnZoom_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
btnZoom_1.setText("Zoom-");

There is 4 event because it's a combinaison of CONTROL and ADD

Now I put that code into a child shell and the widget's event fires only 1 of 10

I believe you that it works but I have no idea why it works only 1 of 10.

Maybe Linux can't handle events coming from child shells?

This would kill my project Sad

Have a nice day

Nicolas
Re: Posting event from linux doesn't work like with windows [message #1716417 is a reply to message #1716338] Thu, 03 December 2015 15:32 Go to previous messageGo to next message
Eclipse UserFriend
First, don't use embedded constants like 0x40000 and 0x100002d -- use SWT.* constants.

Second, calling setFocus() triggers a change, including sending events. Those events have to be processed before you can do your posts as the active widget may be something entirely different. You should wrap your post() calls in an asyncExec().

I believe you can add a debugging filter using Display.addFilter() to print out key events and see which widget the event is being dispatched to.

Brian.
Re: Posting event from linux doesn't work like with windows [message #1716589 is a reply to message #1716417] Sat, 05 December 2015 15:50 Go to previous messageGo to next message
Nicolas DI POL is currently offline Nicolas DI POLFriend
Messages: 9
Registered: December 2015
Junior Member
Hello Brian

I have progressed on the subject and thanks for the trick of display.addfilter(), it helped me a lot

I could figure out that I need to put the setfocus outside the async

Here is my code

private void writeValue(String Keypressed, int KeyCode){
System.out.println("-START-");
BrowserComponent.setFocus();
ParentDisplay.asyncExec(new Runnable(){
@Override
public void run() {
Event MyEvent = new Event();
MyEvent.type = SWT.KeyDown;
MyEvent.keyCode = KeyCode;
ParentDisplay.post(MyEvent);
MyEvent.type = SWT.KeyUp;
ParentDisplay.post(MyEvent);
}
});
System.out.println("-END-");
}

it works in 90% of the cases

if you look the listener, sometimes I don't catch the event

WORKING
Event: [Event {type=15 Browser {} time=3726908 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329855422
Event: [Event {type=1 Browser {} time=3726936 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Key DOWN Listener. Current Time (in ms): 1449329855462
KeyEvent{Browser {} time=3726936 data=null character='f'=0x66 keyCode=0x66 keyLocation=0x0 stateMask=0x0 doit=true}
Event: [Event {type=2 Browser {} time=3726936 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Key UP Listener. Current Time (in ms): 1449329855462
Event: [Event {type=15 Button {f} time=3727474 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329855991
-START-
-END-
WORKING
NOT WORKING
Event: [Event {type=15 Browser {} time=3727601 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329856109
Event: [Event {type=15 Button {f} time=3730454 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329858971
-START-
-END-
Event: [Event {type=15 Browser {} time=3730577 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329859085
Event: [Event {type=15 Button {f} time=3731252 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329859774
-START-
-END-
Event: [Event {type=15 Browser {} time=3731394 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329859904
Event: [Event {type=15 Button {f} time=3732040 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329860572
-START-
-END-
NOT WORKING
WORKING
Event: [Event {type=15 Browser {} time=3732152 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329860767
Event: [Event {type=1 Browser {} time=3732345 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Key DOWN Listener. Current Time (in ms): 1449329860853
KeyEvent{Browser {} time=3732345 data=null character='f'=0x66 keyCode=0x66 keyLocation=0x0 stateMask=0x0 doit=true}
Event: [Event {type=2 Browser {} time=3732345 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Key UP Listener. Current Time (in ms): 1449329860854
Event: [Event {type=15 Button {f} time=3732678 data=null x=0 y=0 width=0 height=0 detail=0}] from Display Focus Listener. Current Time (in ms): 1449329861243
-START-
-END-
WORKING

I'm close to the goal and I hope you can help me to make it works
However, many thanks for your help

Nicolas

Re: Posting event from linux doesn't work like with windows [message #1716658 is a reply to message #1716589] Mon, 07 December 2015 10:35 Go to previous messageGo to next message
Nicolas DI POL is currently offline Nicolas DI POLFriend
Messages: 9
Registered: December 2015
Junior Member
Hello Brian

I found a way to make it work.

I switched my parent and child shells to SWT.ON_TOP

If not, I guess the browser can lost the focus between the moment I set it and the moment I post the event. Maybe the OS did that.

I can keep both of them like this, it's not a problem for my application.

Thanks again for your help

Nicolas
Re: Posting event from linux doesn't work like with windows [message #1716729 is a reply to message #1716658] Mon, 07 December 2015 19:40 Go to previous message
Eclipse UserFriend
My guess is that the asyncExec is running before the browser actually receives the focus:

Quote:

private void writeValue(String Keypressed, int KeyCode){
System.out.println("-START-");
BrowserComponent.setFocus();
ParentDisplay.asyncExec(new Runnable(){
@Override
public void run() {


You could add a filter to output the focus change events. As you've discovered, posting events is tricky Smile

Brian.
Previous Topic:no swt.jar in Mars
Next Topic:Save composite content as an image or pdf file
Goto Forum:
  


Current Time: Tue Mar 19 07:08:01 GMT 2024

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

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

Back to the top