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 ;{- Code Header
; ==- Basic Info -================================ ; ==- Basic Info -================================
; Name: ListingRawInputDevices.pb ; Name: ListingRawInputDevices.pb
; Author: Herwin Bozet ; Author: Herwin Bozet (NibblePoker)
; ;
; ==- Compatibility -============================= ; ==- Compatibility -=============================
; Compiler version: PureBasic 5.70 (x64) ; Compiler version: PureBasic 6.21 - C Backend (x86/x64)
; Operating system: Windows 10 21H1 (Previous versions untested) ; Operating system: Windows 10 21H1 (Previous versions untested)
; ;
; ==- Sources -=================================== ; ==- Sources -===================================
; https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input ; https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input
; ;
; ==- Links & License -=========================== ; ==- Links & License -===========================
; License: Unlicense ; License: CC0 1.0 Universal (Public Domain)
; GitHub: https://github.com/aziascreations/PB-RawInput ; GitHub: https://github.com/aziascreations/PB-Win32-RawInput
;} ;}
; ------------------------------------------------------------------------------
;- Notes ;- Notes
; Windows may combine some devices into so-called "virtual devices" ; 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 ; For the errors, see: https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes
; ------------------------------------------------------------------------------
;- Compiler Directives ;- Compiler Directives
; EnableExplicit ; EnableExplicit
@@ -31,15 +34,17 @@ CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
CompilerError("ListingRawInputDevices.pb can only be compiled for Windows platforms !") CompilerError("ListingRawInputDevices.pb can only be compiled for Windows platforms !")
CompilerEndIf CompilerEndIf
XIncludeFile "../Includes/RawInput.pbi" XIncludeFile "../Includes/RawInput-Bindings.pbi"
; ------------------------------------------------------------------------------
;- Code ;- Code
;-> Counting RawInput devices ;-> Counting RawInput devices
Define RawInputDeviceCount.i = 0 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 !" Debug "Found "+Str(RawInputDeviceCount)+" RawInput devices !"
Else Else
Debug "Error while counting RawInput devices: "+Str(GetLastError_())+" !" Debug "Error while counting RawInput devices: "+Str(GetLastError_())+" !"
@@ -50,14 +55,14 @@ EndIf
;-> Listing RawInput devices ;-> Listing RawInput devices
; A memory buffer is used since we can't dynamically declare C-style arrays in PB. ; 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 If Not *RawInputDeviceListBuffer
Debug "Failed to allocate memory for *RawInputDeviceListBuffer !" Debug "Failed to allocate memory for *RawInputDeviceListBuffer !"
End 2 End 2
EndIf EndIf
Define ReturnedValue.WinTypes::UINT = RawInput::GetRawInputDeviceList(*RawInputDeviceListBuffer, @RawInputDeviceCount, SizeOf(RawInput::RAWINPUTDEVICELIST)) Define ReturnedValue.UINT = GetRawInputDeviceList_(*RawInputDeviceListBuffer, @RawInputDeviceCount, SizeOf(RAWINPUTDEVICELIST))
If ReturnedValue <> -1 If ReturnedValue <> -1
Debug "Successfully got the list of RawInput devices ! (Received "+Str(ReturnedValue)+" in the buffer)" Debug "Successfully got the list of RawInput devices ! (Received "+Str(ReturnedValue)+" in the buffer)"
Else Else
@@ -71,17 +76,17 @@ For i=0 To RawInputDeviceCount - 1
;-> > Getting an element from the buffer ;-> > Getting an element from the buffer
; From *RawInputDeviceListBuffer as a RAWINPUTDEVICELIST[] C-type array and type-casting it. ; 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 !) ; 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) Debug #CRLF$+"Device #"+Str(i)
; Printing the device's type ; Printing the device's type
Select *RawInputDevice\dwType Select *RawInputDevice\dwType
Case RawInput::#RIM_TYPEHID Case #RIM_TYPEHID
Debug "> Device type: HID" Debug "> Device type: HID"
Case RawInput::#RIM_TYPEKEYBOARD Case #RIM_TYPEKEYBOARD
Debug "> Device type: Keyboard" Debug "> Device type: Keyboard"
Case RawInput::#RIM_TYPEMOUSE Case #RIM_TYPEMOUSE
Debug "> Device type: Mouse" Debug "> Device type: Mouse"
Default Default
; Can happen due to off-by-one errors in loops ! ; 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 RawInputDeviceInterfaceName.s{#MAX_PATH}
Define RawInputDeviceInterfaceNameSize = #MAX_PATH Define RawInputDeviceInterfaceNameSize = #MAX_PATH
If RawInput::GetRawInputDeviceInfo(*RawInputDevice\hDevice, RawInput::#RIDI_DEVICENAME, If GetRawInputDeviceInfo_(*RawInputDevice\hDevice, #RIDI_DEVICENAME, @RawInputDeviceInterfaceName, @RawInputDeviceInterfaceNameSize) < 0
@RawInputDeviceInterfaceName, @RawInputDeviceInterfaceNameSize) < 0
Debug " > Error: Failed to properly query the device's interface name !" Debug " > Error: Failed to properly query the device's interface name !"
HasEncounteredAnError = #True HasEncounteredAnError = #True
EndIf EndIf
; Getting the device's info ; Getting the device's info
Define RawInputDeviceInfo.RawInput::tagRID_DEVICE_INFO Define RawInputDeviceInfo.tagRID_DEVICE_INFO
Define RawInputDeviceInfoSize = SizeOf(RawInput::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 @RawInputDeviceInfo, @RawInputDeviceInfoSize) < 0
Debug " > Error: Failed to properly query the device's info !" Debug " > Error: Failed to properly query the device's info !"
HasEncounteredAnError = #True HasEncounteredAnError = #True
@@ -129,7 +133,7 @@ For i=0 To RawInputDeviceCount - 1
Debug " > Interface name: "+RawInputDeviceInterfaceName Debug " > Interface name: "+RawInputDeviceInterfaceName
Select RawInputDeviceInfo\dwType Select RawInputDeviceInfo\dwType
Case RawInput::#RIM_TYPEHID Case #RIM_TYPEHID
Debug " > Device type: HID" Debug " > Device type: HID"
Debug " > Vendor ID: 0x"+RSet(Hex(RawInputDeviceInfo\hid\dwProductId), 4, "0") Debug " > Vendor ID: 0x"+RSet(Hex(RawInputDeviceInfo\hid\dwProductId), 4, "0")
Debug " > Product ID: 0x"+RSet(Hex(RawInputDeviceInfo\hid\dwVendorId), 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) " | 0d"+Str(RawInputDeviceInfo\hid\dwVersionNumber)
;usUsagePage and usUsage are not covered here ! ;usUsagePage and usUsage are not covered here !
Case RawInput::#RIM_TYPEKEYBOARD Case #RIM_TYPEKEYBOARD
Debug " > Device type: Keyboard" Debug " > Device type: Keyboard"
Select RawInputDeviceInfo\keyboard\dwType Select RawInputDeviceInfo\keyboard\dwType
Case RawInput::#RI_KEYBOARDTYPE_101 Case #RI_KEYBOARDTYPE_101
; Same as #RI_KEYBOARDTYPE_102 ; Same as #RI_KEYBOARDTYPE_102
Debug " > Keyboard type: Enhanced 101- or 102-key keyboards (and compatibles)" 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" Debug " > Keyboard type: Japanese Keyboard"
Case RawInput::#RI_KEYBOARDTYPE_KOREAN Case #RI_KEYBOARDTYPE_KOREAN
Debug " > Keyboard type: Korean Keyboard" Debug " > Keyboard type: Korean Keyboard"
Case RawInput::#RI_KEYBOARDTYPE_UNKNOWN Case #RI_KEYBOARDTYPE_UNKNOWN
Debug " > Keyboard type: Unknown type or HID keyboard" Debug " > Keyboard type: Unknown type or HID keyboard"
Default Default
; Can easily be encountered with the "\\?\Microsoft Keyboard RID\..." devices ! ; 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 " > Function key count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfFunctionKeys)
Debug " > LED indicator count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfIndicators) Debug " > LED indicator count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfIndicators)
Debug " > Total Key count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfKeysTotal) Debug " > Total Key count: "+Str(RawInputDeviceInfo\keyboard\dwNumberOfKeysTotal)
Case RawInput::#RIM_TYPEMOUSE Case #RIM_TYPEMOUSE
Debug " > Device type: Mouse" Debug " > Device type: Mouse"
; May not properly reflect the mouse's abilities ! ; May not properly reflect the mouse's abilities !
Debug " > Device ID properties: 0b"+RSet(Bin(RawInputDeviceInfo\mouse\dwId, #PB_Long), 4*8, "0") 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" Debug " > HID mouse"
EndIf EndIf
If RawInputDeviceInfo\mouse\dwId & RawInput::#WHEELMOUSE_HID_HARDWARE If RawInputDeviceInfo\mouse\dwId & #WHEELMOUSE_HID_HARDWARE
Debug " > HID wheel mouse" Debug " > HID wheel mouse"
EndIf EndIf
If RawInputDeviceInfo\mouse\dwId & RawInput::#HORIZONTAL_WHEEL_PRESENT If RawInputDeviceInfo\mouse\dwId & #HORIZONTAL_WHEEL_PRESENT
Debug " > Mouse with horizontal wheel" Debug " > Mouse with horizontal wheel"
EndIf 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 ; Ignoring some of the "undocumented" bit fields from: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/ntddmou.h
+486
View File
@@ -0,0 +1,486 @@
;{- Code Header
; ==- Basic Info -================================
; Name: RawInput-Bindings.pbi
; Version: 2.0.0
; Author: Herwin Bozet (NibblePoker)
;
; ==- Compatibility -=============================
; 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: 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"
; https://stackoverflow.com/a/10331763/4135541
; ------------------------------------------------------------------------------
;- Compiler Directives
EnableExplicit
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
CompilerError("This include can only be used on Windows platforms !")
CompilerEndIf
; ------------------------------------------------------------------------------
;- Typedefs
;{
;-> Generic Win32
UndefineMacro BOOL
Macro BOOL : l : EndMacro
UndefineMacro BYTE
Macro BYTE : a : EndMacro
UndefineMacro DWORD
Macro DWORD : l : EndMacro
UndefineMacro HANDLE
Macro HANDLE : i : EndMacro
UndefineMacro HWND
Macro HWND : HANDLE : EndMacro
UndefineMacro INT
Macro INT : l : EndMacro
UndefineMacro UINT
Macro UINT : l : EndMacro ; Not 100% sure
UndefineMacro UINT_PTR
Macro UINT_PTR : i : EndMacro
UndefineMacro LONG_PTR
Macro LONG_PTR : i : EndMacro
UndefineMacro LPVOID
Macro LPVOID : i : EndMacro
UndefineMacro LRESULT
Macro LRESULT : LONG_PTR : EndMacro
UndefineMacro PUINT
Macro PUINT : i : EndMacro
UndefineMacro ULONG
Macro ULONG : l : EndMacro
UndefineMacro USHORT
Macro USHORT : u : EndMacro
UndefineMacro WPARAM
Macro WPARAM : UINT_PTR : EndMacro
;-> RawInput specific
UndefineMacro HRAWINPUT
Macro HRAWINPUT : HANDLE : EndMacro
UndefineMacro PCRAWINPUTDEVICE
Macro PCRAWINPUTDEVICE : i : EndMacro ; TMP
;}
; ------------------------------------------------------------------------------
;- Structures & Structure Macros
;{
; https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input#structures
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawmouse
Structure tagRAWMOUSE_DUMMYSTRUCTNAME Align #PB_Structure_AlignC
usButtonFlags.USHORT
usButtonData.USHORT
EndStructure
Structure tagRAWMOUSE Align #PB_Structure_AlignC
usFlags.USHORT
StructureUnion
ulButtons.ULONG
DUMMYSTRUCTNAME.tagRAWMOUSE_DUMMYSTRUCTNAME
EndStructureUnion
ulRawButtons.ULONG
lLastX.LONG
lLastY.LONG
ulExtraInformation.ULONG
EndStructure
Macro RAWMOUSE : tagRAWMOUSE : EndMacro
Macro PRAWMOUSE : i : EndMacro
Macro LPRAWMOUSE : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawkeyboard
Structure tagRAWKEYBOARD Align #PB_Structure_AlignC
MakeCode.USHORT
Flags.USHORT
Reserved.USHORT
VKey.USHORT
Message.UINT
ExtraInformation.ULONG
EndStructure
Macro RAWKEYBOARD : tagRAWKEYBOARD : EndMacro
Macro PRAWKEYBOARD : i : EndMacro
Macro LPRAWKEYBOARD : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawhid
; Each WM_INPUT can indicate several inputs, but all of the inputs come from the same HID.
; The size of the bRawData array is dwSizeHid * dwCount.
Structure tagRAWHID Align #PB_Structure_AlignC
dwSizeHid.DWORD
dwCount.DWORD
bRawData.BYTE[1]
EndStructure
Macro RAWHID : tagRAWHID : EndMacro
Macro PRAWHID : i : EndMacro
Macro LPRAWHID : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputheader
; Size may vary due to use of .i types (x86 not verified fully !)
Structure tagRAWINPUTHEADER Align #PB_Structure_AlignC
dwType.DWORD
dwSize.DWORD
hDevice.HANDLE
wParam.WPARAM
EndStructure
Macro RAWINPUTHEADER : tagRAWINPUTHEADER : EndMacro
Macro PRAWINPUTHEADER : i : EndMacro
Macro LPRAWINPUTHEADER : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinput
Structure tagRAWINPUT Align #PB_Structure_AlignC
header.RAWINPUTHEADER
StructureUnion
mouse.RAWMOUSE
keyboard.RAWKEYBOARD
hid.RAWHID
EndStructureUnion
EndStructure
Macro RAWINPUT : tagRAWINPUT : EndMacro
Macro PRAWINPUT : i : EndMacro
Macro LPRAWINPUT : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputdevice
; Size may vary due to use of .i types (x86 not verified fully !)
Structure tagRAWINPUTDEVICE Align #PB_Structure_AlignC
usUsagePage.USHORT
usUsage.USHORT
dwFlags.DWORD
hwndTarget.HWND
EndStructure
Macro RAWINPUTDEVICE : tagRAWINPUTDEVICE : EndMacro
Macro PRAWINPUTDEVICE : i : EndMacro
Macro LPRAWINPUTDEVICE : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputdevicelist
; Size may vary due to use of .i types (x86 not verified fully !)
Structure tagRAWINPUTDEVICELIST Align #PB_Structure_AlignC
hDevice.HANDLE
dwType.DWORD
EndStructure
Macro RAWINPUTDEVICELIST : tagRAWINPUTDEVICELIST : EndMacro
Macro PRAWINPUTDEVICELIST : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info_hid
Structure tagRID_DEVICE_INFO_HID Align #PB_Structure_AlignC
dwVendorId.DWORD
dwProductId.DWORD
dwVersionNumber.DWORD
usUsagePage.USHORT
usUsage.USHORT
EndStructure
Macro RID_DEVICE_INFO_HID : tagRID_DEVICE_INFO_HID : EndMacro
Macro PRID_DEVICE_INFO_HID : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info_keyboard
Structure tagRID_DEVICE_INFO_KEYBOARD Align #PB_Structure_AlignC
dwType.DWORD
dwSubType.DWORD
dwKeyboardMode.DWORD
dwNumberOfFunctionKeys.DWORD
dwNumberOfIndicators.DWORD
dwNumberOfKeysTotal.DWORD
EndStructure
Macro RID_DEVICE_INFO_KEYBOARD : tagRID_DEVICE_INFO_KEYBOARD : EndMacro
Macro PRID_DEVICE_INFO_KEYBOARD : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info_mouse
Structure tagRID_DEVICE_INFO_MOUSE Align #PB_Structure_AlignC
dwId.DWORD
dwNumberOfButtons.DWORD
dwSampleRate.DWORD
fHasHorizontalWheel.BOOL
EndStructure
Macro RID_DEVICE_INFO_MOUSE : tagRID_DEVICE_INFO_MOUSE : EndMacro
Macro PRID_DEVICE_INFO_MOUSE : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info
Structure tagRID_DEVICE_INFO Align #PB_Structure_AlignC
cbSize.DWORD
dwType.DWORD
StructureUnion
mouse.RID_DEVICE_INFO_MOUSE
keyboard.RID_DEVICE_INFO_KEYBOARD
hid.RID_DEVICE_INFO_HID
EndStructureUnion
EndStructure
Macro RID_DEVICE_INFO : tagRID_DEVICE_INFO : EndMacro
Macro PRID_DEVICE_INFO : i : EndMacro
Macro LPRID_DEVICE_INFO : i : EndMacro
;}
; ------------------------------------------------------------------------------
;- Constants
; Type of raw input (tagRAWINPUTHEADER\dwType & tagRID_DEVICE_INFO\dwType)
#RIM_TYPEMOUSE = 0 ; Raw input comes from the mouse.
#RIM_TYPEKEYBOARD = 1 ; Raw input comes from the keyboard.
#RIM_TYPEHID = 2 ; Raw input comes from some device that is not a keyboard or a mouse.
; The mouse state (tagRAWMOUSE\usFlags)
#MOUSE_MOVE_RELATIVE = $00 ; Mouse movement data is relative to the last mouse position.
#MOUSE_MOVE_ABSOLUTE = $01 ; Mouse movement data is based on absolute position.
#MOUSE_VIRTUAL_DESKTOP = $02 ; Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system).
#MOUSE_ATTRIBUTES_CHANGED = $04 ; Mouse attributes changed
; Application needs to query the mouse attributes.
#MOUSE_MOVE_NOCOALESCE = $08 ; This mouse movement event was not coalesced. Mouse movement events can be coalescened by default.
; Windows XP/2000: This value is not supported.
; The mouse state (tagRAWMOUSE\DUMMYSTRUCTNAME\usButtonFlags)
#RI_MOUSE_BUTTON_1_DOWN = $0001 ; Left button changed to down.
#RI_MOUSE_BUTTON_1_UP = $0002 ; Left button changed to up.
#RI_MOUSE_BUTTON_2_DOWN = $0004 ; Right button changed to down.
#RI_MOUSE_BUTTON_2_UP = $0008 ; Right button changed to up.
#RI_MOUSE_BUTTON_3_DOWN = $0010 ; Middle button changed to down.
#RI_MOUSE_BUTTON_3_UP = $0020 ; Middle button changed to up.
#RI_MOUSE_BUTTON_4_DOWN = $0040 ; XBUTTON1 changed to down.
#RI_MOUSE_BUTTON_4_UP = $0080 ; XBUTTON1 changed to up.
#RI_MOUSE_BUTTON_5_DOWN = $0100 ; XBUTTON2 changed to down.
#RI_MOUSE_BUTTON_5_UP = $0200 ; XBUTTON2 changed to up.
#RI_MOUSE_WHEEL = $0400 ; Raw input comes from a mouse wheel
#RI_MOUSE_HWHEEL = $0800 ; Raw input comes from a horizontal mouse wheel.
; The wheel delta is stored in usButtonData.
; A positive value indicates that the wheel was rotated to the right.
; A negative value indicates that the wheel was rotated to the left.
; Windows XP/2000: This value is not supported.
#RI_MOUSE_LEFT_BUTTON_DOWN = #RI_MOUSE_BUTTON_1_DOWN
#RI_MOUSE_LEFT_BUTTON_UP = #RI_MOUSE_BUTTON_1_UP
#RI_MOUSE_RIGHT_BUTTON_DOWN = #RI_MOUSE_BUTTON_2_DOWN
#RI_MOUSE_RIGHT_BUTTON_UP = #RI_MOUSE_BUTTON_2_UP
#RI_MOUSE_MIDDLE_BUTTON_DOWN = #RI_MOUSE_BUTTON_3_DOWN
#RI_MOUSE_MIDDLE_BUTTON_UP = #RI_MOUSE_BUTTON_3_UP
; TODO: Keyboard Flags
; Mode flag (tagRAWINPUTDEVICE\dwFlags)
#RIDEV_REMOVE = $00000001 ; If set, this removes the top level collection from the inclusion list.
; This tells the operating system to stop reading from a device which matches the top level collection.
#RIDEV_EXCLUDE = $00000010 ; If set, this specifies the top level collections to exclude when reading a complete usage page.
; This flag only affects a TLC whose usage page is already specified with #RIDEV_PAGEONLY.
#RIDEV_PAGEONLY = $00000020 ; If set, this specifies all devices whose top level collection is from the specified usUsagePage.
; Note that usUsage must be zero. To exclude a particular top level collection, use #RIDEV_EXCLUDE.
#RIDEV_NOLEGACY = $00000030 ; If set, this prevents any devices specified by usUsagePage or usUsage from generating legacy messages.
; This is only for the mouse and keyboard.
#RIDEV_INPUTSINK = $00000100 ; If set, this enables the caller to receive the input even when the caller is not in the foreground.
; Note that hwndTarget must be specified.
#RIDEV_CAPTUREMOUSE = $00000200 ; If set, the mouse button click does not activate the other window.
; #RIDEV_CAPTUREMOUSE can be specified only if #RIDEV_NOLEGACY is specified for a mouse device.
#RIDEV_NOHOTKEYS = $00000200 ; If set, the application-defined keyboard device hotkeys are not handled.
; However, the system hotkeys; for example, ALT+TAB and CTRL+ALT+DEL, are still handled.
; By default, all keyboard hotkeys are handled.
; #RIDEV_NOHOTKEYS can be specified even if #RIDEV_NOLEGACY is not specified and hwndTarget is NULL.
#RIDEV_APPKEYS = $00000400 ; If set, the application command keys are handled.
; #RIDEV_APPKEYS can be specified only if #RIDEV_NOLEGACY is specified for a keyboard device.
#RIDEV_EXINPUTSINK = $00001000 ; If set, this enables the caller to receive input in the background only if the foreground application does not process it.
; In other words, if the foreground application is not registered for raw input, then the background application that is registered will receive the input.
; Windows XP: This flag is not supported until Windows Vista
#RIDEV_DEVNOTIFY = $00002000 ; If set, this enables the caller to receive WM_INPUT_DEVICE_CHANGE notifications for device arrival and device removal.
; Windows XP: This flag is not supported until Windows Vista
; The type of device (tagRAWINPUTDEVICELIST\dwType)
#RIM_TYPEMOUSE = 0 ; The device is a mouse.
#RIM_TYPEKEYBOARD = 1 ; The device is a keyboard.
#RIM_TYPEHID = 2 ; The device is an HID that is not a keyboard and not a mouse.
; The type of keyboard (tagRID_DEVICE_INFO_KEYBOARD\dwType)
#RI_KEYBOARDTYPE_101 = $4 ; Enhanced 101- or 102-key keyboards (and compatibles)
#RI_KEYBOARDTYPE_JAPANESE = $7 ; Japanese Keyboard
#RI_KEYBOARDTYPE_KOREAN = $8 ; Korean Keyboard
#RI_KEYBOARDTYPE_UNKNOWN = $51 ; Unknown type or HID keyboard
#RI_KEYBOARDTYPE_102 = #RI_KEYBOARDTYPE_101
; For information about keyboard types, subtypes, scan code modes, and related keyboard layouts,
; see the documentation in kbd.h, ntdd8042.h and ntddkbd.h headers in Windows SDK, and the Keyboard Layout Samples.
; The bitfield of the mouse device identification properties (tagRID_DEVICE_INFO_MOUSE\dwId)
; Some "undocummented" constants were gotten from: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/ntddmou.h
#MOUSE_INPORT_HARDWARE = $0001
#MOUSE_I8042_HARDWARE = $0002
#MOUSE_SERIAL_HARDWARE = $0004
#BALLPOINT_I8042_HARDWARE = $0008
#BALLPOINT_SERIAL_HARDWARE = $0010
#WHEELMOUSE_I8042_HARDWARE = $0020
#WHEELMOUSE_SERIAL_HARDWARE = $0040
#MOUSE_HID_HARDWARE = $0080 ; HID mouse
#WHEELMOUSE_HID_HARDWARE = $0100 ; HID wheel mouse
#HORIZONTAL_WHEEL_PRESENT = $8000 ; Mouse with horizontal wheel
; ------------------------------------------------------------------------------
;- Imports
;{
; Note: It could be possible to use the one from PureBasic itself too.
CompilerIf #PB_Compiler_Processor <> #PB_Processor_x64 And #PB_Compiler_Processor <> #PB_Processor_x86
CompilerError("Unable to compile for the current CPU architecture !")
CompilerEndIf
; Documentation:
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-defrawinputproc
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputbuffer
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdata
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdeviceinfoa
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdeviceinfow
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdevicelist
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getregisteredrawinputdevices
; * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerrawinputdevices
Import "User32.lib"
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
DefRawInputProc_.LRESULT(*paRawInput, nInput.INT, cbSizeHeader.UINT) As "_DefRawInputProc@12"
GetRawInputBuffer_.UINT(pData.PRAWINPUT, pcbSize.PUINT, cbSizeHeader.UINT) As "_GetRawInputBuffer@12"
GetRawInputData_.UINT(hRawInput.HRAWINPUT, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT, cbSizeHeader.UINT) As "_GetRawInputData@20"
CompilerIf #PB_Compiler_Unicode
GetRawInputDeviceInfo_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "_GetRawInputDeviceInfoW@16"
CompilerElse
GetRawInputDeviceInfo_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "_GetRawInputDeviceInfoA@16"
CompilerEndIf
GetRawInputDeviceInfoA_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "_GetRawInputDeviceInfoA@16"
GetRawInputDeviceInfoW_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "_GetRawInputDeviceInfoW@16"
GetRawInputDeviceList_.UINT(pRawInputDeviceList.PRAWINPUTDEVICELIST, puiNumDevices.PUINT, cbSize.UINT) As "_GetRawInputDeviceList@12"
GetRegisteredRawInputDevices_.UINT(pRawInputDevices.PRAWINPUTDEVICE, puiNumDevices.PUINT, cbSize.UINT) As "_GetRegisteredRawInputDevices@12"
RegisterRawInputDevices_.BOOL(pRawInputDevices.PCRAWINPUTDEVICE, uiNumDevices.UINT, cbSize.UINT) As "_RegisterRawInputDevices@12"
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
DefRawInputProc_.LRESULT(*paRawInput, nInput.INT, cbSizeHeader.UINT) As "DefRawInputProc"
GetRawInputBuffer_.UINT(pData.PRAWINPUT, pcbSize.PUINT, cbSizeHeader.UINT) As "GetRawInputBuffer"
GetRawInputData_.UINT(hRawInput.HRAWINPUT, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT, cbSizeHeader.UINT) As "GetRawInputData"
CompilerIf #PB_Compiler_Unicode
GetRawInputDeviceInfo_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "GetRawInputDeviceInfoW"
CompilerElse
GetRawInputDeviceInfo_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "GetRawInputDeviceInfoA"
CompilerEndIf
GetRawInputDeviceInfoA_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "GetRawInputDeviceInfoA"
GetRawInputDeviceInfoW_.UINT(hDevice.HANDLE, uiCommand.UINT, pData.LPVOID, pcbSize.PUINT) As "GetRawInputDeviceInfoW"
GetRawInputDeviceList_.UINT(pRawInputDeviceList.PRAWINPUTDEVICELIST, puiNumDevices.PUINT, cbSize.UINT) As "GetRawInputDeviceList"
GetRegisteredRawInputDevices_.UINT(pRawInputDevices.PRAWINPUTDEVICE, puiNumDevices.PUINT, cbSize.UINT) As "GetRegisteredRawInputDevices"
RegisterRawInputDevices_.BOOL(pRawInputDevices.PCRAWINPUTDEVICE, uiNumDevices.UINT, cbSize.UINT) As "RegisterRawInputDevices"
CompilerEndIf
EndImport
;}
; ------------------------------------------------------------------------------
;-> Function Constants
; GetRawInputData - uiCommand
#RID_HEADER = $10000005 ; Get the header information from the RAWINPUT structure.
#RID_INPUT = $10000003 ; Get the raw data from the RAWINPUT structure.
; GetRawInputDeviceInfo - uiCommand
#RIDI_PREPARSEDDATA = $20000005 ; pData is a PHIDP_PREPARSED_DATA pointer to a buffer for a top-level collection's preparsed data.
#RIDI_DEVICENAME = $20000007 ; pData points to a string that contains the device interface name.
; If this device is opened with Shared Access Mode then you can call CreateFile with this name to open a HID collection and use returned handle for calling ReadFile to read input reports and WriteFile to send output reports.
; For this uiCommand only, the value in pcbSize is the character count (not the byte count).
#RIDI_DEVICEINFO = $2000000b ; pData points to an RID_DEVICE_INFO structure.
; ------------------------------------------------------------------------------
;- Tests
CompilerIf #PB_Compiler_IsMainFile
Debug "Structure Sizes:"
Debug "SizeOf(tagRAWMOUSE) = "+Str(SizeOf(tagRAWMOUSE))
Debug "SizeOf(tagRAWKEYBOARD) = "+Str(SizeOf(tagRAWKEYBOARD))
Debug "SizeOf(tagRAWHID) = "+Str(SizeOf(tagRAWHID))
Debug "SizeOf(tagRAWINPUTHEADER) = "+Str(SizeOf(tagRAWINPUTHEADER))
Debug "SizeOf(tagRAWINPUT) = "+Str(SizeOf(tagRAWINPUT))
Debug "SizeOf(tagRAWINPUTDEVICE) = "+Str(SizeOf(tagRAWINPUTDEVICE))
Debug "SizeOf(tagRAWINPUTDEVICELIST) = "+Str(SizeOf(tagRAWINPUTDEVICELIST))
Debug "SizeOf(tagRID_DEVICE_INFO_HID) = "+Str(SizeOf(tagRID_DEVICE_INFO_HID))
Debug "SizeOf(tagRID_DEVICE_INFO_KEYBOARD) = "+Str(SizeOf(tagRID_DEVICE_INFO_KEYBOARD))
Debug "SizeOf(tagRID_DEVICE_INFO_MOUSE) = "+Str(SizeOf(tagRID_DEVICE_INFO_MOUSE))
Debug "SizeOf(tagRID_DEVICE_INFO) = "+Str(SizeOf(tagRID_DEVICE_INFO))
; Expected result in C:
; x64:
; SizeOf(tagRAWMOUSE): 24
; SizeOf(tagRAWKEYBOARD): 16
; SizeOf(tagRAWHID): 12
; SizeOf(tagRAWINPUTHEADER): 24
; SizeOf(tagRAWINPUT): 48
; SizeOf(tagRAWINPUTDEVICE): 16
; SizeOf(tagRAWINPUTDEVICELIST): 16
; SizeOf(tagRID_DEVICE_INFO_HID): 16
; SizeOf(tagRID_DEVICE_INFO_KEYBOARD): 24
; SizeOf(tagRID_DEVICE_INFO_MOUSE): 16
; SizeOf(tagRID_DEVICE_INFO): 32
; x86:
; SizeOf(tagRAWMOUSE): 24
; SizeOf(tagRAWKEYBOARD): 16
; SizeOf(tagRAWHID): 12
; SizeOf(tagRAWINPUTHEADER): 16
; SizeOf(tagRAWINPUT): 40
; SizeOf(tagRAWINPUTDEVICE): 12
; SizeOf(tagRAWINPUTDEVICELIST): 8
; SizeOf(tagRID_DEVICE_INFO_HID): 16
; SizeOf(tagRID_DEVICE_INFO_KEYBOARD): 24
; SizeOf(tagRID_DEVICE_INFO_MOUSE): 16
; SizeOf(tagRID_DEVICE_INFO): 32
; ARM64:
; ???
CompilerEndIf
+41
View File
@@ -0,0 +1,41 @@
;{- Code Header
; ==- Basic Info -================================
; Name: RawInput-Wrapper.pbi
; Version: 2.0.0
; Author: Herwin Bozet (NibblePoker)
;
; ==- Compatibility -=============================
; 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: CC0 1.0 Universal (Public Domain)
; GitHub: https://github.com/aziascreations/PB-Win32-RawInput
;}
; ------------------------------------------------------------------------------
;- Notes
; ???
; ------------------------------------------------------------------------------
;- Compiler Directives
EnableExplicit
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
CompilerError("This include can only be used on Windows platforms !")
CompilerEndIf
XIncludeFile "./RawInput-Bindings.pbi"
; ------------------------------------------------------------------------------
;- ???
-398
View File
@@ -1,398 +0,0 @@
;{- Code Header
; ==- Basic Info -================================
; Name: RawInput.pbi
; Version: 1.0.1
; Author: Herwin Bozet
;
; ==- Compatibility -=============================
; Compiler version: PureBasic 5.70 (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
;}
;- Notes
; Windows may combine some devices into so-called "virtual devices"
; https://stackoverflow.com/a/10331763/4135541
; FIXME: Not tested on X86 !
;- Compiler Directives
;EnableExplicit
XIncludeFile "./WinTypes.pbi"
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
CompilerError("RawInput.pbi can only be compiled for Windows platforms !")
CompilerEndIf
;- Module Declaration
DeclareModule RawInput
;-> Semver Data
#Version_Major = 1
#Version_Minor = 0
#Version_Patch = 1
#Version_Label$ = ""
#Version$ = "1.0.1";+"-"+#Version_Label$
;-> Library Path Declaration
; Note: It could be possible to use the one from PureBasic itself too.
#LibPath_User32_x86$ = "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86\User32.lib"
#LibPath_User32_x64$ = "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64\User32.lib"
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
#LibPath_User32$ = #LibPath_User32_x86$
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
#LibPath_User32$ = #LibPath_User32_x64$
CompilerElse
CompilerError("Unable to compile for the current CPU architecture !")
CompilerEndIf
;-> Structures & Structure Macros
; https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input#structures
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawmouse
Structure tagRAWMOUSE_DUMMYSTRUCTNAME Align #PB_Structure_AlignC
usButtonFlags.WinTypes::USHORT
usButtonData.WinTypes::USHORT
EndStructure
Structure tagRAWMOUSE Align #PB_Structure_AlignC
usFlags.WinTypes::USHORT
StructureUnion
ulButtons.WinTypes::ULONG
DUMMYSTRUCTNAME.tagRAWMOUSE_DUMMYSTRUCTNAME
EndStructureUnion
ulRawButtons.WinTypes::ULONG
lLastX.WinTypes::LONG
lLastY.WinTypes::LONG
ulExtraInformation.WinTypes::ULONG
EndStructure
Macro RAWMOUSE : RawInput::tagRAWMOUSE : EndMacro
Macro PRAWMOUSE : i : EndMacro
Macro LPRAWMOUSE : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawkeyboard
Structure tagRAWKEYBOARD Align #PB_Structure_AlignC
MakeCode.WinTypes::USHORT
Flags.WinTypes::USHORT
Reserved.WinTypes::USHORT
VKey.WinTypes::USHORT
Message.WinTypes::UINT
ExtraInformation.WinTypes::ULONG
EndStructure
Macro RAWKEYBOARD : RawInput::tagRAWKEYBOARD : EndMacro
Macro PRAWKEYBOARD : i : EndMacro
Macro LPRAWKEYBOARD : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawhid
; Each WM_INPUT can indicate several inputs, but all of the inputs come from the same HID.
; The size of the bRawData array is dwSizeHid * dwCount.
Structure tagRAWHID Align #PB_Structure_AlignC
dwSizeHid.WinTypes::DWORD
dwCount.WinTypes::DWORD
bRawData.WinTypes::BYTE[1]
EndStructure
Macro RAWHID : RawInput::tagRAWHID : EndMacro
Macro PRAWHID : i : EndMacro
Macro LPRAWHID : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputheader
; Size may vary due to use of .i types (x86 not verified fully !)
Structure tagRAWINPUTHEADER Align #PB_Structure_AlignC
dwType.WinTypes::DWORD
dwSize.WinTypes::DWORD
hDevice.WinTypes::HANDLE
wParam.WinTypes::WPARAM
EndStructure
Macro RAWINPUTHEADER : RawInput::tagRAWINPUTHEADER : EndMacro
Macro PRAWINPUTHEADER : i : EndMacro
Macro LPRAWINPUTHEADER : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinput
Structure tagRAWINPUT Align #PB_Structure_AlignC
header.RAWINPUTHEADER
StructureUnion
mouse.RAWMOUSE
keyboard.RAWKEYBOARD
hid.RAWHID
EndStructureUnion
EndStructure
Macro RAWINPUT : RawInput::tagRAWINPUT : EndMacro
Macro PRAWINPUT : i : EndMacro
Macro LPRAWINPUT : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputdevice
; Size may vary due to use of .i types (x86 not verified fully !)
Structure tagRAWINPUTDEVICE Align #PB_Structure_AlignC
usUsagePage.WinTypes::USHORT
usUsage.WinTypes::USHORT
dwFlags.WinTypes::DWORD
hwndTarget.WinTypes::HWND
EndStructure
Macro RAWINPUTDEVICE : RawInput::tagRAWINPUTDEVICE : EndMacro
Macro PRAWINPUTDEVICE : i : EndMacro
Macro LPRAWINPUTDEVICE : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rawinputdevicelist
; Size may vary due to use of .i types (x86 not verified fully !)
Structure tagRAWINPUTDEVICELIST Align #PB_Structure_AlignC
hDevice.WinTypes::HANDLE
dwType.WinTypes::DWORD
EndStructure
Macro RAWINPUTDEVICELIST : RawInput::tagRAWINPUTDEVICELIST : EndMacro
Macro PRAWINPUTDEVICELIST : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info_hid
Structure tagRID_DEVICE_INFO_HID Align #PB_Structure_AlignC
dwVendorId.WinTypes::DWORD
dwProductId.WinTypes::DWORD
dwVersionNumber.WinTypes::DWORD
usUsagePage.WinTypes::USHORT
usUsage.WinTypes::USHORT
EndStructure
Macro RID_DEVICE_INFO_HID : RawInput::tagRID_DEVICE_INFO_HID : EndMacro
Macro PRID_DEVICE_INFO_HID : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info_keyboard
Structure tagRID_DEVICE_INFO_KEYBOARD Align #PB_Structure_AlignC
dwType.WinTypes::DWORD
dwSubType.WinTypes::DWORD
dwKeyboardMode.WinTypes::DWORD
dwNumberOfFunctionKeys.WinTypes::DWORD
dwNumberOfIndicators.WinTypes::DWORD
dwNumberOfKeysTotal.WinTypes::DWORD
EndStructure
Macro RID_DEVICE_INFO_KEYBOARD : RawInput::tagRID_DEVICE_INFO_KEYBOARD : EndMacro
Macro PRID_DEVICE_INFO_KEYBOARD : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info_mouse
Structure tagRID_DEVICE_INFO_MOUSE Align #PB_Structure_AlignC
dwId.WinTypes::DWORD
dwNumberOfButtons.WinTypes::DWORD
dwSampleRate.WinTypes::DWORD
fHasHorizontalWheel.WinTypes::BOOL
EndStructure
Macro RID_DEVICE_INFO_MOUSE : RawInput::tagRID_DEVICE_INFO_MOUSE : EndMacro
Macro PRID_DEVICE_INFO_MOUSE : i : EndMacro
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-rid_device_info
Structure tagRID_DEVICE_INFO Align #PB_Structure_AlignC
cbSize.WinTypes::DWORD
dwType.WinTypes::DWORD
StructureUnion
mouse.RID_DEVICE_INFO_MOUSE
keyboard.RID_DEVICE_INFO_KEYBOARD
hid.RID_DEVICE_INFO_HID
EndStructureUnion
EndStructure
Macro RID_DEVICE_INFO : RawInput::tagRID_DEVICE_INFO : EndMacro
Macro PRID_DEVICE_INFO : i : EndMacro
Macro LPRID_DEVICE_INFO : i : EndMacro
;-> Structure Constants
; Type of raw input (tagRAWINPUTHEADER\dwType & tagRID_DEVICE_INFO\dwType)
#RIM_TYPEMOUSE = 0 ; Raw input comes from the mouse.
#RIM_TYPEKEYBOARD = 1 ; Raw input comes from the keyboard.
#RIM_TYPEHID = 2 ; Raw input comes from some device that is not a keyboard or a mouse.
; The mouse state (tagRAWMOUSE\usFlags)
#MOUSE_MOVE_RELATIVE = $00 ; Mouse movement data is relative to the last mouse position.
#MOUSE_MOVE_ABSOLUTE = $01 ; Mouse movement data is based on absolute position.
#MOUSE_VIRTUAL_DESKTOP = $02 ; Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system).
#MOUSE_ATTRIBUTES_CHANGED = $04 ; Mouse attributes changed
; Application needs to query the mouse attributes.
#MOUSE_MOVE_NOCOALESCE = $08 ; This mouse movement event was not coalesced. Mouse movement events can be coalescened by default.
; Windows XP/2000: This value is not supported.
; The mouse state (tagRAWMOUSE\DUMMYSTRUCTNAME\usButtonFlags)
#RI_MOUSE_BUTTON_1_DOWN = $0001 ; Left button changed to down.
#RI_MOUSE_BUTTON_1_UP = $0002 ; Left button changed to up.
#RI_MOUSE_BUTTON_2_DOWN = $0004 ; Right button changed to down.
#RI_MOUSE_BUTTON_2_UP = $0008 ; Right button changed to up.
#RI_MOUSE_BUTTON_3_DOWN = $0010 ; Middle button changed to down.
#RI_MOUSE_BUTTON_3_UP = $0020 ; Middle button changed to up.
#RI_MOUSE_BUTTON_4_DOWN = $0040 ; XBUTTON1 changed to down.
#RI_MOUSE_BUTTON_4_UP = $0080 ; XBUTTON1 changed to up.
#RI_MOUSE_BUTTON_5_DOWN = $0100 ; XBUTTON2 changed to down.
#RI_MOUSE_BUTTON_5_UP = $0200 ; XBUTTON2 changed to up.
#RI_MOUSE_WHEEL = $0400 ; Raw input comes from a mouse wheel
#RI_MOUSE_HWHEEL = $0800 ; Raw input comes from a horizontal mouse wheel.
; The wheel delta is stored in usButtonData.
; A positive value indicates that the wheel was rotated to the right.
; A negative value indicates that the wheel was rotated to the left.
; Windows XP/2000: This value is not supported.
#RI_MOUSE_LEFT_BUTTON_DOWN = #RI_MOUSE_BUTTON_1_DOWN
#RI_MOUSE_LEFT_BUTTON_UP = #RI_MOUSE_BUTTON_1_UP
#RI_MOUSE_RIGHT_BUTTON_DOWN = #RI_MOUSE_BUTTON_2_DOWN
#RI_MOUSE_RIGHT_BUTTON_UP = #RI_MOUSE_BUTTON_2_UP
#RI_MOUSE_MIDDLE_BUTTON_DOWN = #RI_MOUSE_BUTTON_3_DOWN
#RI_MOUSE_MIDDLE_BUTTON_UP = #RI_MOUSE_BUTTON_3_UP
; TODO: Keyboard Flags
; Mode flag (tagRAWINPUTDEVICE\dwFlags)
#RIDEV_REMOVE = $00000001 ; If set, this removes the top level collection from the inclusion list.
; This tells the operating system to stop reading from a device which matches the top level collection.
#RIDEV_EXCLUDE = $00000010 ; If set, this specifies the top level collections to exclude when reading a complete usage page.
; This flag only affects a TLC whose usage page is already specified with #RIDEV_PAGEONLY.
#RIDEV_PAGEONLY = $00000020 ; If set, this specifies all devices whose top level collection is from the specified usUsagePage.
; Note that usUsage must be zero. To exclude a particular top level collection, use #RIDEV_EXCLUDE.
#RIDEV_NOLEGACY = $00000030 ; If set, this prevents any devices specified by usUsagePage or usUsage from generating legacy messages.
; This is only for the mouse and keyboard.
#RIDEV_INPUTSINK = $00000100 ; If set, this enables the caller to receive the input even when the caller is not in the foreground.
; Note that hwndTarget must be specified.
#RIDEV_CAPTUREMOUSE = $00000200 ; If set, the mouse button click does not activate the other window.
; #RIDEV_CAPTUREMOUSE can be specified only if #RIDEV_NOLEGACY is specified for a mouse device.
#RIDEV_NOHOTKEYS = $00000200 ; If set, the application-defined keyboard device hotkeys are not handled.
; However, the system hotkeys; for example, ALT+TAB and CTRL+ALT+DEL, are still handled.
; By default, all keyboard hotkeys are handled.
; #RIDEV_NOHOTKEYS can be specified even if #RIDEV_NOLEGACY is not specified and hwndTarget is NULL.
#RIDEV_APPKEYS = $00000400 ; If set, the application command keys are handled.
; #RIDEV_APPKEYS can be specified only if #RIDEV_NOLEGACY is specified for a keyboard device.
#RIDEV_EXINPUTSINK = $00001000 ; If set, this enables the caller to receive input in the background only if the foreground application does not process it.
; In other words, if the foreground application is not registered for raw input, then the background application that is registered will receive the input.
; Windows XP: This flag is not supported until Windows Vista
#RIDEV_DEVNOTIFY = $00002000 ; If set, this enables the caller to receive WM_INPUT_DEVICE_CHANGE notifications for device arrival and device removal.
; Windows XP: This flag is not supported until Windows Vista
; The type of device (tagRAWINPUTDEVICELIST\dwType)
#RIM_TYPEMOUSE = 0 ; The device is a mouse.
#RIM_TYPEKEYBOARD = 1 ; The device is a keyboard.
#RIM_TYPEHID = 2 ; The device is an HID that is not a keyboard and not a mouse.
; The type of keyboard (tagRID_DEVICE_INFO_KEYBOARD\dwType)
#RI_KEYBOARDTYPE_101 = $4 ; Enhanced 101- or 102-key keyboards (and compatibles)
#RI_KEYBOARDTYPE_JAPANESE = $7 ; Japanese Keyboard
#RI_KEYBOARDTYPE_KOREAN = $8 ; Korean Keyboard
#RI_KEYBOARDTYPE_UNKNOWN = $51 ; Unknown type or HID keyboard
#RI_KEYBOARDTYPE_102 = #RI_KEYBOARDTYPE_101
; For information about keyboard types, subtypes, scan code modes, and related keyboard layouts,
; see the documentation in kbd.h, ntdd8042.h and ntddkbd.h headers in Windows SDK, and the Keyboard Layout Samples.
; The bitfield of the mouse device identification properties (tagRID_DEVICE_INFO_MOUSE\dwId)
; Some "undocummented" constants were gotten from: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/ntddmou.h
#MOUSE_INPORT_HARDWARE = $0001
#MOUSE_I8042_HARDWARE = $0002
#MOUSE_SERIAL_HARDWARE = $0004
#BALLPOINT_I8042_HARDWARE = $0008
#BALLPOINT_SERIAL_HARDWARE = $0010
#WHEELMOUSE_I8042_HARDWARE = $0020
#WHEELMOUSE_SERIAL_HARDWARE = $0040
#MOUSE_HID_HARDWARE = $0080 ; HID mouse
#WHEELMOUSE_HID_HARDWARE = $0100 ; HID wheel mouse
#HORIZONTAL_WHEEL_PRESENT = $8000 ; Mouse with horizontal wheel
;-> Remaining Type Macros
Macro HRAWINPUT : WinTypes::HANDLE : EndMacro
Macro PCRAWINPUTDEVICE : i : EndMacro ; TMP
;-> Library Importation
Import #LibPath_User32$
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-defrawinputproc
;DefRawInputProc.WinTypes::LRESULT(*paRawInput.PRAWINPUT, nInput.WinTypes::INT, cbSizeHeader.WinTypes::UINT)
DefRawInputProc.WinTypes::LRESULT(*paRawInput, nInput.WinTypes::INT, cbSizeHeader.WinTypes::UINT)
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputbuffer
GetRawInputBuffer.WinTypes::UINT(pData.PRAWINPUT, pcbSize.WinTypes::PUINT, cbSizeHeader.WinTypes::UINT)
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdata
GetRawInputData.WinTypes::UINT(hRawInput.HRAWINPUT, uiCommand.WinTypes::UINT, pData.WinTypes::LPVOID,
pcbSize.WinTypes::PUINT, cbSizeHeader.WinTypes::UINT)
CompilerIf #PB_Compiler_Unicode
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdeviceinfow
GetRawInputDeviceInfo.WinTypes::UINT(hDevice.WinTypes::HANDLE, uiCommand.WinTypes::UINT,
pData.WinTypes::LPVOID, pcbSize.WinTypes::PUINT ) As "GetRawInputDeviceInfoW"
CompilerElse
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdeviceinfoa
GetRawInputDeviceInfo.WinTypes::UINT(hDevice.WinTypes::HANDLE, uiCommand.WinTypes::UINT,
pData.WinTypes::LPVOID, pcbSize.WinTypes::PUINT ) As "GetRawInputDeviceInfoA"
CompilerEndIf
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getrawinputdevicelist
GetRawInputDeviceList.WinTypes::UINT(pRawInputDeviceList.PRAWINPUTDEVICELIST, puiNumDevices.WinTypes::PUINT,
cbSize.WinTypes::UINT)
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getregisteredrawinputdevices
GetRegisteredRawInputDevices.WinTypes::UINT(pRawInputDevices.PRAWINPUTDEVICE, puiNumDevices.WinTypes::PUINT,
cbSize.WinTypes::UINT)
; https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerrawinputdevices
RegisterRawInputDevices.WinTypes::Bool(pRawInputDevices.PCRAWINPUTDEVICE, uiNumDevices.WinTypes::UINT,
cbSize.WinTypes::UINT)
EndImport
;-> Function Constants
; GetRawInputData - uiCommand
#RID_HEADER = $10000005 ; Get the header information from the RAWINPUT structure.
#RID_INPUT = $10000003 ; Get the raw data from the RAWINPUT structure.
; GetRawInputDeviceInfo - uiCommand
#RIDI_PREPARSEDDATA = $20000005 ; pData is a PHIDP_PREPARSED_DATA pointer to a buffer for a top-level collection's preparsed data.
#RIDI_DEVICENAME = $20000007 ; pData points to a string that contains the device interface name.
; If this device is opened with Shared Access Mode then you can call CreateFile with this name to open a HID collection and use returned handle for calling ReadFile to read input reports and WriteFile to send output reports.
; For this uiCommand only, the value in pcbSize is the character count (not the byte count).
#RIDI_DEVICEINFO = $2000000b ; pData points to an RID_DEVICE_INFO structure.
EndDeclareModule
;- Module Definition
Module RawInput
; Nothing...
EndModule
;- Tests
CompilerIf #PB_Compiler_IsMainFile
Debug "SizeOf(tagRAWMOUSE) = "+Str(SizeOf(RawInput::tagRAWMOUSE))
Debug "SizeOf(tagRAWKEYBOARD) = "+Str(SizeOf(RawInput::tagRAWKEYBOARD))
Debug "SizeOf(tagRAWHID) = "+Str(SizeOf(RawInput::tagRAWHID))
Debug "SizeOf(tagRAWINPUTHEADER) = "+Str(SizeOf(RawInput::tagRAWINPUTHEADER))
Debug "SizeOf(tagRAWINPUT) = "+Str(SizeOf(RawInput::tagRAWINPUT))
Debug "SizeOf(tagRAWINPUTDEVICE) = "+Str(SizeOf(RawInput::tagRAWINPUTDEVICE))
Debug "SizeOf(tagRAWINPUTDEVICELIST) = "+Str(SizeOf(RawInput::tagRAWINPUTDEVICELIST))
Debug "SizeOf(tagRID_DEVICE_INFO_HID) = "+Str(SizeOf(RawInput::tagRID_DEVICE_INFO_HID))
Debug "SizeOf(tagRID_DEVICE_INFO_KEYBOARD) = "+Str(SizeOf(RawInput::tagRID_DEVICE_INFO_KEYBOARD))
Debug "SizeOf(tagRID_DEVICE_INFO_MOUSE) = "+Str(SizeOf(RawInput::tagRID_DEVICE_INFO_MOUSE))
Debug "SizeOf(tagRID_DEVICE_INFO) = "+Str(SizeOf(RawInput::tagRID_DEVICE_INFO))
CompilerEndIf
-155
View File
@@ -1,155 +0,0 @@
;{- Code Header
; ==- Basic Info -================================
; Name: WinTypes.pbi
; Version: 1.1.0
; Author: Herwin Bozet
;
; ==- Compatibility -=============================
; Compiler version: PureBasic 5.70 (x86/x64)
; Operating system: Windows 10 21H1 (Previous versions untested)
;
; ==- Sources -===================================
; https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types
;
; ==- Links & License -===========================
; License: Unlicense
;}
;- Compiler Options
EnableExplicit
;- Module Declaration
DeclareModule WinTypes
;-> Semver Data
#Version_Major = 1
#Version_Minor = 1
#Version_Patch = 0
#Version_Label$ = ""
#Version$ = "1.1.0";+"-"+#Version_Label$
;-> Macros
Macro APIENTRY : WINAPI : EndMacro
Macro ATOM : WORD : EndMacro
Macro BOOL : l : EndMacro
Macro BOOLEAN : BYTE : EndMacro
Macro BYTE : a : EndMacro
Macro CCHAR : b : EndMacro
Macro CHAR : b : EndMacro
Macro COLORREF : l : EndMacro
Macro DWORD : l : EndMacro
Macro DWORDLONG : q : EndMacro
Macro DWORD_PTR : i : EndMacro
Macro DWORD32 : l : EndMacro
Macro DWORD64 : q : EndMacro
Macro FLOAT : f : EndMacro
Macro HACCEL : HANDLE : EndMacro
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Macro HALF_PTR : u : EndMacro
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
Macro HALF_PTR : l : EndMacro
CompilerEndIf
Macro HANDLE : i : EndMacro
Macro HBITMAP : HANDLE : EndMacro
Macro HBRUSH : HANDLE : EndMacro
Macro HCOLORSPACE : HANDLE : EndMacro
Macro HCONV : HANDLE : EndMacro
Macro HCONVLIST : HANDLE : EndMacro
Macro HCURSOR : HICON : EndMacro
Macro HDC : HANDLE : EndMacro
Macro HDDEDATA : HANDLE : EndMacro
Macro HDESK : HANDLE : EndMacro
Macro HDROP : HANDLE : EndMacro
Macro HDWP : HANDLE : EndMacro
Macro HENHMETAFILE : HANDLE : EndMacro
Macro HFILE : l : EndMacro
Macro HFONT : HANDLE : EndMacro
Macro HGDIOBJ : HANDLE : EndMacro
Macro HGLOBAL : HANDLE : EndMacro
Macro HHOOK : HANDLE : EndMacro
Macro HICON : HANDLE : EndMacro
Macro HINSTANCE : HANDLE : EndMacro
Macro HKEY : HANDLE : EndMacro
Macro HKL : HANDLE : EndMacro
Macro HLOCAL : HANDLE : EndMacro
Macro HMENU : HANDLE : EndMacro
Macro HMETAFILE : HANDLE : EndMacro
Macro HMODULE : HINSTANCE : EndMacro
Macro HMONITOR : HANDLE : EndMacro ; if(WINVER >= 0x0500) typedef HANDLE HMONITOR;
Macro HPALETTE : HANDLE : EndMacro
Macro HPEN : HANDLE : EndMacro
Macro HRESULT : LONG : EndMacro
Macro HRGN : HANDLE : EndMacro
Macro HRSRC : HANDLE : EndMacro
Macro HSZ : HANDLE : EndMacro
Macro HWINSTA : HANDLE : EndMacro
Macro HWND : HANDLE : EndMacro
Macro INT : l : EndMacro
Macro LANGID : WORD : EndMacro
Macro LCID : DWORD : EndMacro
Macro LCTYPE : DWORD : EndMacro
Macro LGRPID : DWORD : EndMacro
; Can be used somewhat interchangeably, but can cause issues with PB's compiler.
;Macro LPCWSTR : s : EndMacro
Macro LPCWSTR : i : EndMacro
Macro LPDWORD : i : EndMacro
Macro LONG : l : EndMacro
Macro LONG_PTR : i : EndMacro
Macro LONG32 : l : EndMacro
Macro LONG64 : q : EndMacro
; IDK what the fuck this is...
Macro LPOVERLAPPED : i : EndMacro
Macro LPVOID : i : EndMacro
Macro LRESULT : LONG_PTR : EndMacro
Macro LSTATUS : l : EndMacro
Macro PCWSTR : s : EndMacro
Macro PSTR : s : EndMacro
Macro PDWORD : i : EndMacro
Macro PVOID : i : EndMacro
Macro PHANDLE : i : EndMacro
Macro PULONG : i : EndMacro
Macro PCHAR : i : EndMacro
Macro PUINT : i : EndMacro
Macro UCHAR : a : EndMacro
Macro UINT : l : EndMacro ; Not 100% sure
Macro UINT_PTR : i : EndMacro
Macro UINT8 : a : EndMacro
Macro UINT16 : u : EndMacro
Macro UINT32 : l : EndMacro
Macro UINT64 : q : EndMacro
Macro ULONG : l : EndMacro
Macro ULONGLONG : q : EndMacro
Macro USHORT : u : EndMacro
Macro WCHAR : u : EndMacro
Macro WINAPI : q : EndMacro
Macro WORD : w : EndMacro
Macro WPARAM : UINT_PTR : EndMacro
EndDeclareModule
;- Module Definition
Module WinTypes
; Nothing...
EndModule
+50
View File
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.purebasic.com/namespace" version="1.0" creator="PureBasic 6.40 (Windows - x64)">
<section name="config">
<options closefiles="1" openmode="4" name="PB-RawInput"/>
</section>
<section name="data">
<explorer view="" pattern="0"/>
<log show="1"/>
<lastopen date="2026-07-31 12:16" user="Herwin" host="DESKTOP-N6M1VPH"/>
</section>
<section name="files">
<file name="Includes\RawInput-Bindings.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0" sortindex="999" panelstate="++"/>
<fingerprint md5="bbddefc52c37bc0c53412655a9aa21e4"/>
</file>
<file name="Examples\ListingRawInputDevices.pb">
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="1" panelstate="++"/>
<fingerprint md5="888885163a9bc85be2b5d624ea08bd7e"/>
</file>
<file name="Includes\RawInput-Wrapper.pbi">
<config load="0" scan="1" panel="1" warn="1" lastopen="0" sortindex="999" panelstate="++"/>
<fingerprint md5="458700f3538de019da598f4f2215f2aa"/>
</file>
</section>
<section name="targets">
<target name="ListRawInputDevices - x64" enabled="1" default="1">
<inputfile value="Examples\ListingRawInputDevices.pb"/>
<outputfile value="t1.exe"/>
<compiler version="PureBasic 6.21 - C Backend (Windows - x64)"/>
<executable value="t1.exe"/>
<options debug="1" optimizer="0"/>
<temporaryexe value="source"/>
<format exe="console" cpu="0"/>
<compilecount enable="1" value="3"/>
<buildcount enable="1" value="1"/>
</target>
<target name="ListRawInputDevices - x86" enabled="1" default="0">
<inputfile value="Examples\ListingRawInputDevices.pb"/>
<outputfile value="t2.exe"/>
<compiler version="PureBasic 6.21 - C Backend (Windows - x86)"/>
<executable value="t2.exe"/>
<options debug="1" optimizer="0"/>
<temporaryexe value="source"/>
<format exe="console" cpu="0"/>
<compilecount enable="1" value="1"/>
<buildcount enable="1" value="1"/>
</target>
</section>
</project>
+24 -3
View File
@@ -1,17 +1,38 @@
# PB-RawInput # PureBasic - RawInput
A module to access and use Windows' RawInput API. Set of includes that provides bindings and wrappers for
[Windows' RawInput APIs](https://learn.microsoft.com/en-us/windows/win32/inputdev/raw-input).
> [!NOTE]
> This include is in low maintenance mode. \
> I consider it feature-complete, and unless a bug is found, I don't plan on updating it.
## Usage ## Usage
Adding submodule:
```shell
git submodule add https://github.com/aziascreations/PB-Win32-RawInput.git Includes/PB-Win32-RawInput
```
Pull latest submodule version:
```shell
git submodule update --init --recursive
```
## Examples
Simply include "*[RawInput.pbi](Includes/RawInput.pbi)*" and use the structures, functions and datatypes documented on the [MSDN page](https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input.) with the `RawInput::` prefix. Simply include "*[RawInput.pbi](Includes/RawInput.pbi)*" and use the structures, functions and datatypes documented on the [MSDN page](https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input.) with the `RawInput::` prefix.
## Considerations ## Considerations
* The module has not been tested on x86 platforms * The module has not been tested on x86 platforms
* Some structure fields may not be available on Windows XP, see Microsoft's documentation. * Some structure fields may not be available on Windows XP, see Microsoft's documentation.
* `GetRawInputDeviceInfoA` and `GetRawInputDeviceInfoW` are available under `GetRawInputDeviceInfo`. * `GetRawInputDeviceInfoA` and `GetRawInputDeviceInfoW` are available under `GetRawInputDeviceInfo`.
## Useful Links ## Useful Links
* MSDN page - https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input * MSDN page - https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input
* MSDN page - https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input * MSDN page - https://docs.microsoft.com/en-us/windows/win32/inputdev/raw-input
## License ## License
[Unlicense](LICENSE) All the code in this repo is released in the [Public Domain](LICENSE).