2

I am interested in reading gamepad input, specifically a gamepad with the layout of a wired xbox 360 controller, with C on a linux machine. I understand that this can be done in a variety of ways, however I was wondering what is the modern method of accomplishing this. As I understand it, evdev is the 'future' while the Joystick API is legacy. Using libudev I am able to find attached gamepads and detect when they are connected and disconnected:

// skipping setup code ....
char const* val = udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
if (val != NULL && strcmp(val, "1") == 0) {
  char const* devfs_path = udev_device_get_devnode(udev_device);
}
// .....
struct udev_device* device = udev_monitor_recieve_device(udev_monitor); 
char const* action = udev_device_get_action(device);
if (strcmp(action, "add") == 0) {
  // .....
}
if (strcmp(action, "remove") == 0) {
  // .....
}

The crux of my question lies in the best way to read button presses and axis movement. Currently, I am unsure whether to use struct js_event or struct input_event. In truth, I was hoping to be able to do this with the same check for connected and removed gamepads with libudev. If this is not possible, which is the most forward-thinking approach? Thanks.

4

1 回答 1

0

根据内核文档

鼓励较新的客户端切换到通用事件 (evdev) 接口。

所需控制器的特定映射可以在linux input kernel community docs中找到

因此,使用struct input_event

于 2019-02-06T20:40:58.883 回答