【问题标题】:Simulate mouse motion on linux wayland在 linux wayland 上模拟鼠标运动
【发布时间】:2015-09-12 02:36:30
【问题描述】:

我从我的网络接收 xy 数据,我想在 Wayland 上使用 linux 控制鼠标位置。

我见过许多使用 X 库或 X 应用程序的源代码,但它不适用于 Wayland。我还查看了 libinput 和 evedev,但我没有找到任何关于如何创建/模拟鼠标的代码示例。

【问题讨论】:

  • 我还没有测试解决方案,但是感谢您的帖子,我在我们的 jUnit 测试中遇到了同样的问题..

标签: linux mouseevent input-devices wayland evdev


【解决方案1】:

Uinput 就是答案。

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

【讨论】:

  • 知道如何在无需使用外部库/工具的情况下执行此类任务吗?
  • @Jewenile 我不这么认为。 UInput 有优势为 X 和 wayland 工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
相关资源
最近更新 更多