Simulate mouse movement on linux wayland

I get xy data from my network and I would like to control the mouse position using linux on wayland.

I have seen many sources using X libs or X applications, but it will not work on wayland. I also look at libinput and evedev, but I find no code example on how to create / model a mouse.

+4
source share
1 answer

Uinput is the answer.

void initMouse(){
  fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
  ioctl(fd, UI_SET_EVBIT, EV_KEY);
  ioctl(fd, UI_SET_KEYBIT, BTN_LEFT);
  ioctl(fd, UI_SET_EVBIT, EV_ABS);
  ioctl(fd, UI_SET_ABSBIT, ABS_X);
  ioctl(fd, UI_SET_ABSBIT, ABS_Y);

  struct uinput_user_dev uidev;
  memset(&uidev,0,sizeof(uidev));
  snprintf(uidev.name,UINPUT_MAX_NAME_SIZE,"HolusionMouse");
  uidev.id.bustype = BUS_USB;
  uidev.id.version = 1;
  uidev.id.vendor = 0x1;
  uidev.id.product = 0x1;
  uidev.absmin[ABS_X] = 0;
  uidev.absmax[ABS_X] = 1080;
  uidev.absmin[ABS_Y] = 0;
  uidev.absmax[ABS_Y] = 1080;
  write(fd, &uidev, sizeof(uidev));
  ioctl(fd, UI_DEV_CREATE);

  usleep(100000);
}

And update:

struct input_event ev[2], evS;
 memset(ev, 0, sizeof(ev ));
 ev[0].type = EV_ABS;
 ev[0].code = ABS_X;
 ev[0].value = 100;
 ev[1].type = EV_ABS;
 ev[1].code = ABS_Y;
 ev[1].value = 100;
 write(fd, ev, sizeof(ev));

 memset(&evS,0,sizeof(struct input_event));
 evS.type = EV_SYN;
 write(fd, &evS, sizeof(struct input_event));

 usleep(10000);
+1
source

All Articles