Here one way :
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
Global Const $tagMSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
Global $hHook, $hStub_MouseProc
HotKeySet("{ESC}", _Exit)
OnAutoItExitRegister(Cleanup)
Example()
Func Example()
Local $hMod
$hStub_MouseProc = DllCallbackRegister(_MouseProc, "long", "int;wparam;lparam")
$hMod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hMod)
While True
Sleep(100)
WEnd
EndFunc ;==>Example
Func _MouseProc($nCode, $wParam, $lParam)
Local $xevent
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
Local $tMouseHOOKS = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam)
Local $ptx = DllStructGetData($tMouseHOOKS, "X")
Local $pty = DllStructGetData($tMouseHOOKS, "Y")
Local $mouseData = DllStructGetData($tMouseHOOKS, "mousedata")
Local $flags = DllStructGetData($tMouseHOOKS, "flags")
Switch $wParam
Case $WM_MOUSEMOVE
$xevent = "Mouse Move"
Case $WM_MOUSEWHEEL
If _WinAPI_HiWord($mouseData) > 0 Then
$xevent = "Wheel Forward"
Else
$xevent = "Wheel Backward"
EndIf
Case $WM_LBUTTONDOWN
Return 1 ; (will block)
$xevent = "Left Down"
Case $WM_LBUTTONUP
Return 1 ; (will block)
$xevent = "Left Up"
Case $WM_RBUTTONDOWN
$xevent = "Right Down"
Case $WM_RBUTTONUP
$xevent = "Right Up"
Case $WM_MBUTTONDBLCLK
$xevent = "Double Wheel Click"
Case $WM_MBUTTONDOWN
$xevent = "Wheel Down"
Case $WM_MBUTTONUP
$xevent = "Wheel Up"
EndSwitch
ConsoleWrite($xevent & @CRLF)
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_MouseProc
Func Cleanup()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_MouseProc)
EndFunc ;==>Cleanup
Func _Exit()
Exit
EndFunc ;==>_Exit