#include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
HotKeySet("{Esc}", "_Exit")
Global $dll_user32 = DllOpen('user32.dll')
Global $dll_kernel32 = DllOpen('kernel32.dll')
Global $hForm, $tRID, $pRID
Global $Data, $Flags
Global Const $mb_1d = 0x0001 ; d - нажтие, u - отпускание
Global Const $mb_1u = 0x0002
Global Const $mb_2d = 0x0004
Global Const $mb_2u = 0x0008
Global Const $mb_3d = 0x0010
Global Const $mb_3u = 0x0020
Global Const $mb_4d = 0x0040
Global Const $mb_4u = 0x0080
Global Const $mb_5d = 0x0100
Global Const $mb_5u = 0x0200
Global Const $wh = 0x0400
Global $aMouse[6] = [6, $mb_1d, $mb_2d, $mb_3d, $mb_4d, $mb_5d] ; Только нажатие
; Global $Funcs[5] = [ 5, 'Func1', 'Func2']
; Create GUI
$hForm = GUICreate('MyGUI', 160, 212, @DesktopWidth -179, @DesktopHeight -283, _
BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST)
$tRID = DllStructCreate($tagRAWINPUTDEVICE)
DllStructSetData($tRID, 'UsagePage', 0x01) ; Generic Desktop Controls
DllStructSetData($tRID, 'Usage', 0x02) ; Mouse
DllStructSetData($tRID, 'Flags', $RIDEV_INPUTSINK)
DllStructSetData($tRID, 'hTarget', $hForm)
$pRID = DllStructGetPtr($tRID)
; Register HID input to obtain row input from mice
_WinAPI_RegisterRawInputDevices($pRID)
; Register WM_INPUT message
GUIRegisterMsg($WM_INPUT, 'WM_INPUT')
;GUISetState()
While 1
;~ If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
DllCall($dll_kernel32, 'DWORD', 'Sleep', 'int', 1) ; Sleep 1ms
WEnd
Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam)
Local $tRIM = DllStructCreate($tagRAWINPUTMOUSE)
; _WinAPI_GetRawInputData()
DllCall($dll_user32, 'uint', 'GetRawInputData', 'ptr', $lParam, 'uint', $RID_INPUT, 'ptr', _
DllStructGetPtr($tRIM), 'uint*', DllStructGetSize($tRIM), 'uint', 16)
$Flags = DllStructGetData($tRIM, 'ButtonFlags')
For $i = 1 To 5 ; 5 кнопок нажатие только
If BitAND($Flags, $aMouse[$i]) Then
_ButtonDown($i)
EndIf
Next
If BitAND($Flags, $RI_MOUSE_WHEEL) Then
$Data = _WinAPI_WordToShort(DllStructGetData($tRIM, 'ButtonData'))
If $Data > 0 Then
ConsoleWrite('Up')
Else
ConsoleWrite('Down')
EndIf
EndIf
;~ Return ;$GUI_RUNDEFMSG
EndFunc ;==>WM_INPUT
Func _ButtonDown($i)
ConsoleWrite('-> Button' & $i & @CRLF)
Beep(1000, 100)
EndFunc
Func _Exit()
Exit
EndFunc
DllClose($dll_user32)
DllClose($dll_kernel32)