2

I've been using the below API to get data from my game controllers and it's worked fine up until my new controller arrived, which has more than the 32 buttons the API supports (The Windows Game Controller control panel applet doesn't even show them all!)

Public Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Long, pji As JOYINFOEX) As Long

I have API that can send up to 65 bytes to any USB device given the Vendor/Product IDs
I just need to know what bytes to send it. And I can't find any low level documentation like that
I can't use directinput as this is not a game and must run in the background, still allowing use of the controller to games, and I do not want such a large uneeded dependancy

Public Function ReadAndWriteToDevice(MyVendorID As Long, MyProductID As Long, Optional Byte1 As Byte, Optional Byte2 As Byte, Optional Byte3 As Byte, Optional Byte4 As Byte, Optional Byte5 As Byte, Optional Byte6 As Byte, Optional Byte7 As Byte, Optional Byte8 As Byte, Optional ReadBytes As Long = 8, Optional Timeout_in_msec As Integer = 5000) As Byte()
    Dim i As Long
    Dim OutputReportData(65) As Byte
    Dim InputReportData(65) As Byte
    Dim RET() As Byte
    
    OutputReportData(1) = Byte1 ' the code is set up to only send 8 bytes so far but changing it to a max of 65 looks easy
    OutputReportData(2) = Byte2
    OutputReportData(3) = Byte3
    OutputReportData(4) = Byte4
    OutputReportData(5) = Byte5
    OutputReportData(6) = Byte6
    OutputReportData(7) = Byte7
    OutputReportData(8) = Byte8
    
    If MyDeviceDetected = False Then
        MyDeviceDetected = FindTheHid(MyVendorID, MyProductID)
    End If
    
    If MyDeviceDetected Then
        Call WriteToHID(OutputReportData)
        If ReadFromHID(InputReportData, , Timeout_in_msec, False) = -1 Then Exit Function
    End If
    
    If ReadBytes > 64 Or ReadBytes < 1 Then
        ReadAndWriteToDevice = InputReportData
    Else
        ReDim RET(1 To ReadBytes)
        For i = 1 To ReadBytes
            RET(i) = InputReportData(i)
        Next i
        ReadAndWriteToDevice = RET 'InputReportData(1)
    End If
End Function
NeoTechni
  • 158
  • 2
  • 10
  • 1
    This answer suggests using `DirectInput` if your needs exceed `winmm`. https://stackoverflow.com/questions/5849372/joystick-in-win32-application-winmm – User51 Apr 17 '23 at 15:05
  • 1
    Could not use that in the program I am making, the code above is what I need to work. And it does ironically. The documentation of the device made me think it wasn't but the documentation was wrong. – NeoTechni Apr 17 '23 at 17:53

1 Answers1

1

The Game Controller control panel uses DirectInput which is limited to 32 buttons. Which gamepad is this? It's not common for gamepads to have this many buttons.

How can I request input data from a game controller

You don't need to request it. The controller decides when to send input reports. For most controllers, input reports are sent at a regular interval but some controllers only send input reports when an input changes.

The platform API buffers input reports so your application can read them when it's convenient.

On Windows, once you have a file handle for the HID device you can read input reports with ReadFile.

I just need to know what bytes to send it.

If you're only reading inputs you usually don't need to write anything. Output reports are used for features like rumble or LEDs where the host controls the state of the device.

The size and layout of a device's reports is defined in the device's HID report descriptor. If you can get the report descriptor (Windows makes this difficult) then it should give you some hints as to what kind of data the device expects.

nondebug
  • 761
  • 3
  • 5
  • Which gamepad is this? The WinWing MFD-1, which has 48 buttons. Also you're right. I sent all 0's for the bytes and got the data I needed. – NeoTechni May 04 '23 at 23:23
  • 48 buttons?! https://wwsimstore.com/view/goods-details.html?id=417 I see 20 buttons around the edge of the display, plus 4 toggle switches and a dial. I wonder what the other buttons are used for. – nondebug May 05 '23 at 18:00