He estado tratando de usar el módulo del kernel uinput para enviar clics del mouse en rápida sucesión a otros programas.
Esto funciona bien si el retraso entre los clics es de 25 ms o más, pero se interrumpe si es menor. Cuando se rompe, puedo ver los eventos con evtest pero no con xinput . Solo el primer evento parece funcionar normalmente. (Supongo que los eventos posteriores deben perderse de alguna manera entre esos dos. ¿Quizás hay un límite que me he perdido?)
He hecho un pequeño ejemplo que reproduce este comportamiento. (La mayor parte está tomada de la documentación del núcleo )
#include <linux/uinput.h> #include <unistd.h> #include <memory.h> #include <fcntl.h> #define TIME_BETWEEN_CLICKS (25000) // in µs void emit(int fd, int type, int code, int val) { struct input_event ie; ie.type = type; ie.code = code; ie.value = val; ie.time.tv_sec = 0; ie.time.tv_usec = 0; write(fd, &ie, sizeof(ie)); } int main(void) { struct uinput_setup usetup; int i = 50; int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_KEYBIT, BTN_LEFT); memset(&usetup, 0, sizeof(usetup)); usetup.id.bustype = BUS_USB; usetup.id.vendor = 0x1234; /* sample vendor */ usetup.id.product = 0x5678; /* sample product */ strcpy(usetup.name, "Example device"); ioctl(fd, UI_DEV_SETUP, &usetup); ioctl(fd, UI_DEV_CREATE); sleep(2); while (i--) { emit(fd, EV_KEY, BTN_LEFT, 1); emit(fd, EV_SYN, SYN_REPORT, 0); emit(fd, EV_KEY, BTN_LEFT, 0); emit(fd, EV_SYN, SYN_REPORT, 0); usleep(TIME_BETWEEN_CLICKS); } sleep(1); ioctl(fd, UI_DEV_DESTROY); close(fd); return 0; }