简体   繁体   English

从 Xbox 无线控制器读取触发数据

[英]Reading trigger data from xbox wireless controllers

So I'm using hidapi to reading input packets from a few xbox controllers I have and one thing frustrating me is that it reports the left and right triggers as a single "rudder" axis with a uint16_t .因此,我使用 hidapi 从我拥有的几个 Xbox 控制器读取输入数据包,令我沮丧的一件事是,它将左右触发器报告为带有uint16_t的单个“舵”轴。 Is there any sort of packet I can send to change the report structure?我可以发送任何类型的数据包来更改报告结构吗? I know that there are games that can use both triggers at the same time.我知道有些游戏可以同时使用两个触发器。 I guess that the Microsoft answer would be to use DirectInput but I would really like to be able to roll my own.我猜微软的答案是使用 DirectInput,但我真的希望能够自己动手。

#pragma pack(1)
struct xbox_wireless_controller_report {
    static const u8 a = 1;
    static const u8 b = 2;
    static const u8 x = 4;
    static const u8 y = 8;
    static const u8 lb = 16;
    static const u8 rb = 32;
    static const u8 select = 64;
    static const u8 start = 128;

    static const u8 l3 = 1;
    static const u8 r3 = 2;

    u16 left_stick_x;
    u16 left_stick_y;
    u16 right_stick_x;
    u16 right_stick_y;

    u16 rudder;
    
    u8 buttons; // a, b, x, y, lb, rb, select, start
    u8 l3r3;
    u8 dpad;
    u8 unknown[2]; // just here to make 15 bytes
};

static_assert(sizeof(xbox_wireless_controller_report) == 15);

The reason the HID-driver exposed by the Xbox Common Controller have this behavior is for backcompat reasons with some older DirectInput-based racing titles. Xbox Common Controller 暴露的 HID 驱动程序具有此行为的原因是出于与一些较旧的基于 DirectInput 的赛车游戏的反向兼容原因。

The recommendation is to use XINPUT, Windows.Gaming.Input, or GameInput and not legacy DirectInput for the Xbox gamepads.建议使用 XINPUT、Windows.Gaming.Input 或 GameInput,而不是 Xbox 游戏手柄的旧版 DirectInput。

There is an undocumented registry key you can use to manipulate this mapping on your system, but keep in mind that this will impact all use of the Xbox Common Controller via DirectInput.您可以使用未记录的注册表项在系统上操作此映射,但请记住,这将影响通过 DirectInput 对 Xbox Common Controller 的所有使用。 How to detect gamepad triggers both pushed with USB HID API? 如何检测使用 USB HID API 推送的游戏手柄触发器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM