2

I have been trying to use the uinput kernel module to send mouseclicks in quick succession to other programs.

This works fine if the delay between the clicks is 25ms or greater but it breaks if it is lower. When it breaks I can see the events with evtest but not with xinput. Only the first event seems to work normally. (I guess the later events must be somehow lost between those two? Maybe there is a limit that I have missed?)

I have made a small example that reproduces this behaviour. (Most of it is taken from the kernel documentation)

#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;
}
  • https://github.com/mooz/xkeysnail/issues/150 Might be seeing the same issue here, not sure yet. Did you ever find an answer/solution? – Josh Goebel May 29 '22 at 14:44
  • Just read again... if the events come thru to evdev, then there is no issue with uinput - it's working... something higher up is dropping the events, so your question is misworded. – Josh Goebel Jun 09 '22 at 16:05

0 Answers0