为什么 X11 不接受我的虚拟鼠标事件?

为什么 X11 不接受我的虚拟鼠标事件?

float插入鼠标xinput并按照说明操作这里尝试注入鼠标事件。

我正在尝试从鼠标读取事件,将事件代码从 更改为REL_Y并将REL_WHEELREL_X更改为REL_HWHEEL,然后将事件注入回来,以便我可以将鼠标用作二维滚轮。

我认为我已经完成了大部分工作,因为当我运行程序时,我看到event13被添加到/dev/input。在 中dmesg我确实得到了:

input: uinput-sample as /devices/virtual/input/input28

如果我跑步,evtest /dev/input/event13我会得到:

[linux-devkit]:/dev/input> sudo evtest event13

Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x1234 product 0xfedc version 0x1
Input device name: "uinput-sample"
Supported events:
  Event type 0 (EV_SYN)
  Event type 2 (EV_REL)
    Event code 6 (REL_HWHEEL)
    Event code 8 (REL_WHEEL)
Testing ... (interrupt to exit)
Event: time 1457290441.973961, type 2 (EV_REL), code 6 (REL_HWHEEL), value 1
Event: time 1457290441.973961, -------------- SYN_REPORT ------------
Event: time 1457290441.981947, type 2 (EV_REL), code 6 (REL_HWHEEL), value 4
Event: time 1457290441.981947, -------------- SYN_REPORT ------------
Event: time 1457290441.989947, type 2 (EV_REL), code 6 (REL_HWHEEL), value 12
Event: time 1457290441.989947, type 2 (EV_REL), code 8 (REL_WHEEL), value 3
Event: time 1457290441.989947, -------------- SYN_REPORT ------------
Event: time 1457290441.997981, type 2 (EV_REL), code 6 (REL_HWHEEL), value 15
Event: time 1457290441.997981, type 2 (EV_REL), code 8 (REL_WHEEL), value 5
Event: time 1457290441.997981, -------------- SYN_REPORT ------------
Event: time 1457290442.005927, type 2 (EV_REL), code 6 (REL_HWHEEL), value 18
Event: time 1457290442.005927, type 2 (EV_REL), code 8 (REL_WHEEL), value 5
Event: time 1457290442.005927, -------------- SYN_REPORT ------------
Event: time 1457290442.013904, type 2 (EV_REL), code 6 (REL_HWHEEL), value 23
Event: time 1457290442.013904, type 2 (EV_REL), code 8 (REL_WHEEL), value 9
Event: time 1457290442.013904, -------------- SYN_REPORT ------------

但是如果我运行,xinput list我看不到虚拟输入设备。而且 ubuntu 也没有响应该事件。

我错过了什么?

我是否需要为其创建一个从属设备并将其连接进去xinput

答案1

根据BTN_LEFT并且BTN_RIGHT必须设置,否则 xinput 将不会接受 uinput 虚拟设备作为指针从属。

完成后:

ret = ioctl(uinputFD, UI_SET_KEYBIT, BTN_LEFT);
ret = ioctl(uinputFD, UI_SET_KEYBIT, BTN_RIGHT);

虚拟设备出现在xinput中并且运行良好。

因此,即使虚拟设备仅实现鼠标功能的一个子集,比如在我的情况下只有两个滚轮,BTN_LEFT仍然BTN_RIGHT需要设置标志。

相关内容