12-16-07 12:32 PM
Tomdumon@gmail.com writes:
> Hey,
>
> I've been trying to fix this for a while. I was writing a code to send
> a buttonpress in X, left arrow then right arrow. I managed to get that
> working but it was a bit too rapid so I decided to add a sleep
> inbetween that's where the trouble began. It doesn't do anything, it
> doesn't get to the loop. I was thinking it might be to do with the
> signals (it works fine without a delay function). I've even tried
> replacing sleep with other things like comparing cpu times or loops
> but to no success.
>
> Anyway here's the source:
> #include <stdio.h>
> #include <X11/extensions/XTest.h>
> #include <X11/Xlib.h>
> #include <unistd.h>
>
> Display *dpy;
>
> int main()
> {
> sleep(4);
>
> if ((dpy = XOpenDisplay("Glorioso.localdomain:0.0")) == NULL){
> printf("It XXXXed up");
> exit(1);
> }
> while(1){
>
> XTestFakeKeyEvent(dpy, 100, True, CurrentTime);
> XTestFakeKeyEvent(dpy, 100, False, CurrentTime);
> sleep(2);
> XTestFakeKeyEvent(dpy, 102, True, CurrentTime);
> XTestFakeKeyEvent(dpy, 102, False, CurrentTime);
> sleep(2);
> }
>
> XCloseDisplay(dpy);
> }
Xlib is probably buffering the messages to the server. Try adding an
XFlush(dpy) call before each sleep().
--
Måns Rullgård
mans@mansr.com
[ Post a follow-up to this message ]
|