1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <time.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <X11/Xlib.h>
Display *dpy;
int main(int argc, char **argv){
Window agresseur, victime;
XKeyEvent esend;
if(argc == 0){
fprintf(stderr,"Usage : hexagere <numero_de_fenetre>\n");
return -1;
}
victime = atol(argv[0]);
if (! (dpy = XOpenDisplay(":0.0"))) {
fprintf(stderr, "%s: dispositif %s injoignable\n", argv[0],
XDisplayName(NULL));
return -1;
}
agresseur = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
0, 0, 10, 10,
1,
WhitePixel(dpy, DefaultScreen(dpy)),
BlackPixel(dpy, DefaultScreen(dpy)));
XSelectInput(dpy, agresseur, KeyPressMask);
esend.display = dpy;
esend.window = victime;
esend.type = KeyPress;
esend.keycode = XKeysymToKeycode(dpy,XK_2);
esend.state = 0;
srand(time(NULL));
while(1){
if ( XSendEvent(esend.display,esend.window,True, KeyPressMask, (XEvent *)&esend) == True)
fprintf(stdout,"Event sent\n");
XFlush(dpy);
int r = (int)((rand() % 15) + 1);
fprintf(stdout,"Rand : %d\n", r);
sleep(r);
}
return 0;
} |
Partager