Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Ejemplo super simple de cómo floodear con clicks a alguna aplicacion
- * Por ejemplos esos juegos de quien clickea más rápido.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #define nullptr 0
- /* Simplemente para llevarnos mejor con -ansi */
- extern char *optarg;
- extern int optind, opterr, optopt;
- int main(int argc, char* argv[])
- {
- Display* targetDisplay = nullptr; /* Por Ahora no abrimos display, chequeemos cosas primero */
- XEvent windowEvent;
- Window targetWindow = 0;
- int clickButton = 1; /* Izquierdo, por default */
- int clickCount = 1, clickInterval = 0; /* 1 Click, default */
- int clickX =-1, clickY=-1;
- int showUsage = argc<3?1:0;
- int cmdOpt = 0;
- /* Mas feo que unos meros ifs, pero mas estandar y estricto*/
- do{
- /* TODO: Agregar soporte para X e Y*/
- cmdOpt = getopt(argc,argv,":w:b:c:t:h");
- switch(cmdOpt)
- {
- /* Window ID [Obligatorio]*/
- case 'w':
- targetWindow = atoi(optarg);
- break;
- /* Numero de boton [Opcional]*/
- case 'b':
- clickButton = atoi(optarg);
- break;
- /* Numero de clicks [opcional] */
- case 'c':
- clickCount = atoi(optarg);
- break;
- /* Intervalo de tiempo entre click y click [opcional] */
- case 't':
- clickInterval = atoi(optarg);
- break;
- /* Ayuda */
- case 'h':
- showUsage = 1;
- break;
- /* Manejo de unexpected's*/
- case ':':
- fprintf(stderr,"Option -%c requires an argument ! \r\n",optopt);
- showUsage = 1;
- break;
- case '?':
- fprintf(stderr,"Unrecognized option -%c, call without arguments for help on usage\r\n",optopt );
- showUsage = 1;
- break;
- }
- } while ( cmdOpt != -1 && !showUsage);
- /* Mostramos el uso del programa? bueno, mostrar y salir */
- if (showUsage)
- {
- fprintf(stderr,"Usage : %s -w ID [-b Button -c TotalNumClicks -t WaitTimeInmsBetweenClicks] \r\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- /* Pase lo que pase, no podemos tener un ID 0, significa que no se leyo el argumento ... el resto puede estar bien con defaut */
- if (targetWindow == 0 )
- {
- fprintf(stderr,"The Window ID should be different than 0\r\n");
- exit(EXIT_FAILURE);
- }
- /* Ahora si podemos abrir el display */
- targetDisplay = XOpenDisplay(nullptr);
- /* Ok, no hay acceso ? terminamos la ejecucion aca mismo */
- if (targetDisplay == nullptr)
- {
- fprintf(stderr,"XOpenDisplay : Error al abrir el Display !\r\n");
- exit(EXIT_FAILURE);
- }
- /* Estructura de evento a 0 */
- memset(&windowEvent, 0, sizeof(windowEvent));
- /* Se describe solito esto ...*/
- windowEvent.xbutton.button = clickButton;
- windowEvent.xbutton.same_screen = True;
- /* Pido estado del puntero .. */
- XQueryPointer(
- targetDisplay, targetWindow,
- &windowEvent.xbutton.root,
- &windowEvent.xbutton.window,
- &windowEvent.xbutton.x_root,
- &windowEvent.xbutton.y_root,
- &windowEvent.xbutton.x,
- &windowEvent.xbutton.y,
- &windowEvent.xbutton.state
- );
- /*
- * Creo que esto se describe solo ...
- *TODO: IMHO deberia agregar una funcion XWindowExists() para verificar si targetWindow es un ID legitimo revisando la lista de ventanas
- */
- while (clickCount--)
- {
- windowEvent.type = ButtonPress;
- XSendEvent(targetDisplay, targetWindow, True, 0xfff, &windowEvent);
- windowEvent.type = ButtonRelease;
- XSendEvent(targetDisplay, targetWindow, True, 0xfff, &windowEvent);
- XFlush(targetDisplay);
- usleep(clickInterval*1000);
- }
- XCloseDisplay(targetDisplay);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement