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
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.
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.
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.