Revamped include, Removed Module and changed repo URL (#1)

* Removed module, Removed WinTypes, Improved imports and typedefs, Improved readability
Update ListingRawInputDevices.pb, RawInput-Bindings.pbi, RawInput-Wrapper.pbi, and 4 more files

* Improved readme before, merging
Update PB-RawInput.pbp and readme.md

* Updated repo URL
Update ListingRawInputDevices.pb, RawInput-Bindings.pbi, and RawInput-Wrapper.pbi
This commit is contained in:
2026-07-31 12:20:34 +02:00
committed by GitHub
parent 0bd8524686
commit c7779f012f
7 changed files with 633 additions and 584 deletions
+32 -28
View File
@@ -1,20 +1,21 @@
;{- Code Header
; ==- Basic Info -================================
; Name: ListingRawInputDevices.pb
; Author: Herwin Bozet
; Name: ListingRawInputDevices.pb
; Author: Herwin Bozet (NibblePoker)
;
; ==- Compatibility -=============================
; Compiler version: PureBasic 5.70 (x64)
; Compiler version: PureBasic 6.21 - C Backend (x86/x64)
; Operating system: Windows 10 21H1 (Previous versions untested)
;
; ==- Sources -===================================
; https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input
;
; ==- Links & License -===========================
; License: Unlicense
; GitHub: https://github.com/aziascreations/PB-RawInput
; License: CC0 1.0 Universal (Public Domain)
; GitHub: https://github.com/aziascreations/PB-Win32-RawInput
;}
; ------------------------------------------------------------------------------
;- Notes
; Windows may combine some devices into so-called "virtual devices"
@@ -23,6 +24,8 @@
; For the errors, see: https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes
; ------------------------------------------------------------------------------
;- Compiler Directives
; EnableExplicit
@@ -31,15 +34,17 @@ CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
CompilerError("ListingRawInputDevices.pb can only be compiled for Windows platforms !")
CompilerEndIf
XIncludeFile "../Includes/RawInput.pbi"
XIncludeFile "../Includes/RawInput-Bindings.pbi"
; ------------------------------------------------------------------------------
;- Code
;-> Counting RawInput devices
Define RawInputDeviceCount.i = 0
If RawInput::GetRawInputDeviceList(#Null, @RawInputDeviceCount, SizeOf(RawInput::RAWINPUTDEVICELIST)) <> -1
If GetRawInputDeviceList_(#Null, @RawInputDeviceCount, SizeOf(RAWINPUTDEVICELIST)) <> -1
Debug "Found "+Str(RawInputDeviceCount)+" RawInput devices !"
Else
Debug "Error while counting RawInput devices: "+Str(GetLastError_())+" !"
@@ -50,14 +55,14 @@ EndIf
;-> Listing RawInput devices
; A memory buffer is used since we can't dynamically declare C-style arrays in PB.
Define *RawInputDeviceListBuffer = AllocateMemory(SizeOf(RawInput::RAWINPUTDEVICELIST) * RawInputDeviceCount)
Define *RawInputDeviceListBuffer = AllocateMemory(SizeOf(RAWINPUTDEVICELIST) * RawInputDeviceCount)
If Not *RawInputDeviceListBuffer
Debug "Failed to allocate memory for *RawInputDeviceListBuffer !"
End 2
EndIf
Define ReturnedValue.WinTypes::UINT = RawInput::GetRawInputDeviceList(*RawInputDeviceListBuffer, @RawInputDeviceCount, SizeOf(RawInput::RAWINPUTDEVICELIST))
Define ReturnedValue.UINT = GetRawInputDeviceList_(*RawInputDeviceListBuffer, @RawInputDeviceCount, SizeOf(RAWINPUTDEVICELIST))
If ReturnedValue <> -1
Debug "Successfully got the list of RawInput devices ! (Received "+Str(ReturnedValue)+" in the buffer)"
Else
@@ -71,17 +76,17 @@ For i=0 To RawInputDeviceCount - 1
;-> > Getting an element from the buffer
; From *RawInputDeviceListBuffer as a RAWINPUTDEVICELIST[] C-type array and type-casting it.
; tagRAWINPUTDEVICELIST is used instead of RAWINPUTDEVICELIST for the auto-completion. (Same end result !)
Define *RawInputDevice.RawInput::tagRAWINPUTDEVICELIST = *RawInputDeviceListBuffer + (SizeOf(RawInput::RAWINPUTDEVICELIST) * i)
Define *RawInputDevice.tagRAWINPUTDEVICELIST = *RawInputDeviceListBuffer + (SizeOf(RAWINPUTDEVICELIST) * i)
Debug #CRLF$+"Device #"+Str(i)
; Printing the device's type
Select *RawInputDevice\dwType
Case RawInput::#RIM_TYPEHID
Case #RIM_TYPEHID
Debug "> Device type: HID"
Case RawInput::#RIM_TYPEKEYBOARD
Case #RIM_TYPEKEYBOARD
Debug "> Device type: Keyboard"
Case RawInput::#RIM_TYPEMOUSE
Case #RIM_TYPEMOUSE
Debug "> Device type: Mouse"
Default
; Can happen due to off-by-one errors in loops !
@@ -101,17 +106,16 @@ For i=0 To RawInputDeviceCount - 1
Define RawInputDeviceInterfaceName.s{#MAX_PATH}
Define RawInputDeviceInterfaceNameSize = #MAX_PATH
If RawInput::GetRawInputDeviceInfo(*RawInputDevice\hDevice, RawInput::#RIDI_DEVICENAME,
@RawInputDeviceInterfaceName, @RawInputDeviceInterfaceNameSize) < 0
If GetRawInputDeviceInfo_(*RawInputDevice\hDevice, #RIDI_DEVICENAME, @RawInputDeviceInterfaceName, @RawInputDeviceInterfaceNameSize) < 0
Debug " > Error: Failed to properly query the device's interface name !"
HasEncounteredAnError = #True
EndIf
; Getting the device's info
Define RawInputDeviceInfo.RawInput::tagRID_DEVICE_INFO
Define RawInputDeviceInfoSize = SizeOf(RawInput::tagRID_DEVICE_INFO)
Define RawInputDeviceInfo.tagRID_DEVICE_INFO
Define RawInputDeviceInfoSize = SizeOf(tagRID_DEVICE_INFO)
If RawInput::GetRawInputDeviceInfo(*RawInputDevice\hDevice, RawInput::#RIDI_DEVICEINFO,
If GetRawInputDeviceInfo_(*RawInputDevice\hDevice, #RIDI_DEVICEINFO,
@RawInputDeviceInfo, @RawInputDeviceInfoSize) < 0
Debug " > Error: Failed to properly query the device's info !"
HasEncounteredAnError = #True
@@ -129,7 +133,7 @@ For i=0 To RawInputDeviceCount - 1
Debug " > Interface name: "+RawInputDeviceInterfaceName
Select RawInputDeviceInfo\dwType
Case RawInput::#RIM_TYPEHID
Case #RIM_TYPEHID
Debug " > Device type: HID"
Debug " > Vendor ID: 0x"+RSet(Hex(RawInputDeviceInfo\hid\dwProductId), 4, "0")
Debug " > Product ID: 0x"+RSet(Hex(RawInputDeviceInfo\hid\dwVendorId), 4, "0")
@@ -137,18 +141,18 @@ For i=0 To RawInputDeviceCount - 1
" | 0d"+Str(RawInputDeviceInfo\hid\dwVersionNumber)
;usUsagePage and usUsage are not covered here !
Case RawInput::#RIM_TYPEKEYBOARD
Case #RIM_TYPEKEYBOARD
Debug " > Device type: Keyboard"
Select RawInputDeviceInfo\keyboard\dwType
Case RawInput::#RI_KEYBOARDTYPE_101
Case #RI_KEYBOARDTYPE_101
; Same as #RI_KEYBOARDTYPE_102
Debug " > Keyboard type: Enhanced 101- or 102-key keyboards (and compatibles)"
Case RawInput::#RI_KEYBOARDTYPE_JAPANESE
Case #RI_KEYBOARDTYPE_JAPANESE
Debug " > Keyboard type: Japanese Keyboard"
Case RawInput::#RI_KEYBOARDTYPE_KOREAN
Case #RI_KEYBOARDTYPE_KOREAN
Debug " > Keyboard type: Korean Keyboard"
Case RawInput::#RI_KEYBOARDTYPE_UNKNOWN
Case #RI_KEYBOARDTYPE_UNKNOWN
Debug " > Keyboard type: Unknown type or HID keyboard"
Default
; Can easily be encountered with the "\\?\Microsoft Keyboard RID\..." devices !
@@ -164,18 +168,18 @@ For i=0 To RawInputDeviceCount - 1
Debug " > Function key count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfFunctionKeys)
Debug " > LED indicator count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfIndicators)
Debug " > Total Key count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfKeysTotal)
Case RawInput::#RIM_TYPEMOUSE
Case #RIM_TYPEMOUSE
Debug " > Device type: Mouse"
; May not properly reflect the mouse's abilities !
Debug " > Device ID properties: 0b"+RSet(Bin(RawInputDeviceInfo\mouse\dwId, #PB_Long), 4*8, "0")
If RawInputDeviceInfo\mouse\dwId & RawInput::#MOUSE_HID_HARDWARE
If RawInputDeviceInfo\mouse\dwId & #MOUSE_HID_HARDWARE
Debug " > HID mouse"
EndIf
If RawInputDeviceInfo\mouse\dwId & RawInput::#WHEELMOUSE_HID_HARDWARE
If RawInputDeviceInfo\mouse\dwId & #WHEELMOUSE_HID_HARDWARE
Debug " > HID wheel mouse"
EndIf
If RawInputDeviceInfo\mouse\dwId & RawInput::#HORIZONTAL_WHEEL_PRESENT
If RawInputDeviceInfo\mouse\dwId & #HORIZONTAL_WHEEL_PRESENT
Debug " > Mouse with horizontal wheel"
EndIf
; Ignoring some of the "undocumented" bit fields from: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/ntddmou.h