Custom DualSense gampad HID

I am experimenting with sending a output command to the DualSense gamepad to use its adaptive trigger (which the built-in DualSenseGamepadHID from the Input System does not support ATM)

I created my own HID class and register it to the input system with the matcher like:

    static DualSenseHID()
    {
        //InputSystem.RemoveLayout("DualSenseGamepadHID"); // tried to remove the default layout, not working
        InputSystem.RegisterLayout<DualSenseHID>(
            matches: new InputDeviceMatcher()
                .WithInterface("HID")
                .WithCapability("vendorId", 0x54C) // Sony Entertainment.
                .WithCapability("productId", 0xCE6));
    }

    [RuntimeInitializeOnLoadMethod]
    static void Init() { }

But somehow the default DualSense layout is always preferred. From the Input Debug window (as shown in the image), my layout is put into the "Abstract Devices" instead of the "Specific Devices" section.

8782720--1192705--upload_2023-2-5_11-51-43.png

I read some posts mentioning the layout matcher and how to "hijack" the layout, but it seems to only work for unsupported HID, not to a known device like the DualSense.

Could anyone help me a bit on this? Thank you so much!

So apparently it is indeed possible to use the "hijack method" described in https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/manual/Devices.html#matching.

also
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_onFindLayoutForDevice

In the end I simply used the onFindLayoutForDevice method in the constructor and replaced the DualSenseGamepadHID layout name with my layout name. And it worked.

Sorry for my simple question, but I still hope this post could help someone like me some day.

    static DualSenseHID()
    {
        InputSystem.onFindLayoutForDevice +=
        (ref InputDeviceDescription description, string matchedLayout, InputDeviceExecuteCommandDelegate executeDeviceCommand) =>
            {
                if (!string.IsNullOrEmpty(matchedLayout))
                {
                    if (matchedLayout == "DualSenseGamepadHID")
                    {
                        return "DualSenseHID";
                    }
                }

                return null;
            };

        InputSystem.RegisterLayout<DualSenseHID>(
            matches: new InputDeviceMatcher()
                .WithInterface("HID")
                .WithCapability("vendorId", 0x54C) // Sony Entertainment.
                .WithCapability("productId", 0xCE6));
    }
2 Likes