[maemo-developers] How to simulate "drag" event in N900 for controling other applications

From: 百封 whitewinds at 126.com
Date: Mon Jan 17 09:40:16 EET 2011
I need to simulate the "drag" event in N900 to control other applications.
 
When my application is in background, I would like to sent drag event to the foreground application, for example, sending a "drag from left to right" event to control image browsing application to show the previous image. Currently I implement it using following code.Sometimes, it worked. However, sometimes, the drag event will not be responsed.For example, sometimes, when I simulate a drag event to the image browser, the image switching does not happen. But I can felt that a vibration has been triggered. It seems that the device has received a press event (XTestFakeButtonEvent), but the motion (XTestFakeMotionEvent) is ignored.
 
So does anyone know how to solved this problem? Thanks.
 

voidNokiaTouchX11EventHandler::dragLeft()

{

   qDebug()<<"DragLeft";

  Display*dpy=NULL;

  XEventevent;

  inti;

  dpy=XOpenDisplay(NULL);

  XQueryPointer(dpy,RootWindow(dpy,0),

                  &event.xbutton.root,&event.xbutton.window,

                  &event.xbutton.x_root,&event.xbutton.y_root,

                  &event.xbutton.x,&event.xbutton.y,

                  &event.xbutton.state);

  XTestFakeButtonEvent(dpy,1,True,CurrentTime);

  for(i=400;i>=300;i-=50)

  {

          XTestFakeMotionEvent(dpy,-1,i,

                  250,CurrentTime);

          usleep(10000);

          XSync(dpy,0);

  }

  usleep(10000);

  XTestFakeButtonEvent(dpy,1,False,CurrentTime);

  XCloseDisplay(dpy);

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.maemo.org/pipermail/maemo-developers/attachments/20110117/4d40d253/attachment.htm>
More information about the maemo-developers mailing list