在linux wayland上模拟鼠标运动

我从我的网络收到xy数据,我想在wayland上使用
linux控制鼠标位置.

我已经看过很多使用X libs或X app的源代码,但它不适用于Wayland.我也看了libinput和evedev,但我找不到任何关于如何创建/模拟鼠标的代码示例.

最佳答案 输入就是答案.

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);
}

并更新:

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);
点赞