https://www.purebasic.fr/english/viewt ... st#p494812
J'ai modifié rapidement le code pour tester... mais je pense qu'il y a moyen de faire un module facile a utiliser pour l'utiliser dans les jeux
et utiliser 2 souris en même temps.
Si vous voulez essayer branchez 2 souris et bougez les !

Code : Tout sélectionner
EnableExplicit
;{ Raw Input }
; GetRawInputData() command flags
#RID_HEADER = $10000005 ; get header structure
#RID_INPUT = $10000003 ; get whole RAWINPUT structure
; Types of raw input data
#RIM_TYPEMOUSE = 0
#RIM_TYPEKEYBOARD = 1
#RIM_TYPEHID = 2
; RAWINPUTDEVICE flags
#RIDEV_REMOVE = $00000001
#RIDEV_EXCLUDE = $00000010
#RIDEV_PAGEONLY = $00000020
#RIDEV_NOLEGACY = $00000030
#RIDEV_INPUTSINK = $00000100
#RIDEV_CAPTUREMOUSE = $00000200
#RIDEV_NOHOTKEYS = $00000200
#RIDEV_APPKEYS = $00000400
#RIDEV_EXINPUTSINK = $00001000
#RIDEV_DEVNOTIFY = $00002000
; GetRawInputDeviceInfo() flags
#RIDI_PREPARSEDDATA = $20000005 ; returns previously parsed data
#RIDI_DEVICENAME = $20000007 ;- a string containing the device name
#RIDI_DEVICEINFO = $2000000b ;- an RIDI_DEVICE_INFO Structure
Prototype GetRawInputData(hRawInput, uiCommand, *pData.RAWINPUT, *pcbSize, cbSizeHeader)
Prototype RegisterRawInputDevices(*pRawInputDevices.RAWINPUTDEVICE, *uiNumDevices, cbSize)
Prototype GetRawInputDeviceList(*pRawInputDeviceList.RAWINPUTDEVICELIST, *uiNumDevices, cbSize)
Prototype GetRawInputDeviceInfo(hDevice, uiCommand, *pData, *pcbSize)
; import functions
Global User32_dll = OpenLibrary(#PB_Any, "user32.dll")
If IsLibrary(User32_dll)
Global RegisterRawInputDevices.RegisterRawInputDevices = GetFunction(User32_dll, "RegisterRawInputDevices")
Global GetRawInputData.GetRawInputData = GetFunction(User32_dll, "GetRawInputData")
Global GetRawInputDeviceList.GetRawInputDeviceList = GetFunction(User32_dll, "GetRawInputDeviceList")
Global GetRawInputDeviceInfo.GetRawInputDeviceInfo = GetFunction(User32_dll, "GetRawInputDeviceInfoW")
EndIf
;}
Structure myRawMouse
X.l
Y.l
EndStructure
Global NewMap MyRawMouse.myRawMouse()
; windows message processing
Procedure WinCallback (hWnd, Message, WParam, LParam)
Select Message
Case #WM_INPUT: ; Raw Input
Protected pcbSize.l
Protected *pRawData.RAWINPUT
If GetRawInputData(lParam, #RID_INPUT, #Null, @pcbSize, SizeOf(RAWINPUTHEADER)) = 0
*pRawData = AllocateMemory(pcbSize) ; If input is from HID-device, data size can vary
If *pRawData
GetRawInputData(lParam, #RID_INPUT, *pRawData, @pcbSize, SizeOf(RAWINPUTHEADER))
Select *pRawData\header\dwType
Case #RIM_TYPEMOUSE:
; here input is collected
;Debug "Vk " + Str(*pRawData\mouse\ulButtons) + " from device " + Str(*pRawData\header\hDevice)
If Not FindMapElement(MyRawMouse(), Str(*pRawData\header\hDevice))
AddMapElement(MyRawMouse(), Str(*pRawData\header\hDevice))
EndIf
MyRawMouse()\X=MyRawMouse()\X+*pRawData\mouse\lLastX
MyRawMouse()\Y=MyRawMouse()\Y+*pRawData\mouse\lLastY
Debug Str(*pRawData\header\hDevice)+" "+Str(MyRawMouse()\X)+","+Str(MyRawMouse()\Y)
EndSelect
FreeMemory(*pRawData)
EndIf
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure Main ()
Protected WndMain = 123
Protected hWnd = OpenWindow(WndMain, #PB_Ignore, #PB_Ignore, 300, 200, "SOME RAW INPUT HOOK", #PB_Window_Invisible)
; capture window messages
SetWindowCallback(@WinCallback())
; set raw input capture for all mouses and keyboards
Dim Rid.RAWINPUTDEVICE(0)
Rid(0)\usUsagePage = 1
Rid(0)\usUsage = 0
Rid(0)\hwndTarget = hWnd
Rid(0)\dwFlags = #RIDEV_INPUTSINK | #RIDEV_PAGEONLY
If RegisterRawInputDevices (@Rid(), ArraySize(Rid()) + 1, SizeOf(RAWINPUTDEVICE)) = #True
Debug "Press any key on any keyboard ..."
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Else
; Msg("Failed to register devices: " + NameLastError())
EndIf
If IsLibrary(User32_dll)
CloseLibrary(User32_dll)
EndIf
EndProcedure
;;;;;;;;;
Main()
End