我一直在尝试使用 libevdev 创建一个简单的程序来制作一个虚拟设备,该设备将简单地将鼠标每秒在 X 轴上移动 50 个点。程序运行得很好,但是 Xorg 无法识别新创建的虚拟设备。
我想这将是一件微不足道的事情,但我不知道是什么。
Xorgs 的日志说:
[ 5860.310] (II) config/udev: Adding input device test device Mouse (/dev/input/event18)
[ 5860.310] (II) No input driver specified, ignoring this device.
[ 5860.310] (II) This device may have been added with another device file.
该程序:
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
static void check(int i) {
if (i < 0) {
printf("%s\n", strerror(-i));
exit(1);
}
}
int main() {
struct libevdev* evdev = libevdev_new();
libevdev_set_name(evdev, "test device Mouse");
libevdev_set_id_vendor(evdev, 0x1);
libevdev_set_id_product(evdev, 0x1);
libevdev_set_id_version(evdev, 0x1);
libevdev_set_id_bustype(evdev, BUS_USB);
check(libevdev_enable_event_type(evdev, EV_REL));
check(libevdev_enable_event_code(evdev, EV_REL, REL_X, NULL));
check(libevdev_enable_event_code(evdev, EV_REL, REL_Y, NULL));
check(libevdev_enable_event_code(evdev, EV_SYN, SYN_REPORT, NULL));
struct libevdev_uinput* uinput;
check(libevdev_uinput_create_from_device(evdev, LIBEVDEV_UINPUT_OPEN_MANAGED, &uinput));
for (int i = 0; i < 1000; i++) {
check(libevdev_uinput_write_event(uinput, EV_REL, REL_X, 50));
check(libevdev_uinput_write_event(uinput, EV_SYN, SYN_REPORT, 0));
sleep(1);
}
}
我究竟做错了什么?