Generate X events (Xlib)

Lubos Lunak l.lunak at suse.cz
Thu Jun 22 05:05:10 PDT 2006


On Thursday 22 June 2006 11:38, Alexandre Quessy wrote:
> Hi all,
>
> I am trying to generate X events. My main concern is about using that on
> Linux (Debian), but if I could do it on other platforms, namely Mac, this
> could be great.
>
> I tried to generate events using Xlib. I get no error, but my mouse doesn't
> move, and no key seems typed in my X. I wonder if I have done the right
> things. Also, it seems like I would have to create very big structs in
> order to generate some mouse events or such.
...
> int main(int argc, char *argv[]) {
>     Display *display;
>     KeySym keysym;
>     int result;
>     int i;
>
>     keysym = XK_q;
>
>     /* should be hostname:number.screen_number */
>     display = XOpenDisplay(NULL); /* defaults to $DISPLAY */
>     if (display == NULL) {
>         printf("Error : could not open display.\n");
>         return 1;
>     }
>     printf("Display opened successfully.\n");
>     KeyCode keycode = XKeysymToKeycode(display, keysym);
>     for (i=0;i<100;i++) {
>         result = XTestFakeKeyEvent(display, keycode, True, 0);
>         //if (result == 0) printf("failed\n"); else printf("success\n");
>
           XFlush( display );   or the event still sits in the outgoing X 
queue at this moment

>         usleep(100);
>         result = XTestFakeKeyEvent(display, keycode, False, 0);
>         if (result!=0) printf(".");
>         //if (result == 0) printf("failed\n"); else printf("success\n");
>     }
>     printf("\n");

       XCloseDisplay( display ); or the events never make it out of the 
outgoing X queue

 You should check some docs about X architecture and how the communication is 
done asynchronously.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak at suse.cz , l.lunak at kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/



More information about the xorg mailing list