Is there anyone who can help me / explain me how to instal a low lvl hook just for specified running process ?
Theres a UDF file for Autoit that allows u to track mouse
using Callback to a low lvl mouse hook , but its a overall info
Code:
; ~~ Mouse Hook ~~
;For more info, Visit: http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx
;Include GUI Consts
#include <GUIConstants.au3> ;for $GUI_EVENT_CLOSE
#Include <WinAPI.au3> ;for HIWORD
;These constants found in the helpfile under Windows Message Codes
Global Const $WM_MOUSEMOVE = 0x0200 ;mouse move
Global Const $WM_MOUSEWHEEL = 0x020A ;wheel up/down
Global Const $WM_LBUTTONDBLCLK = 0x0203 ;left button
Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $WM_LBUTTONUP = 0x0202
Global Const $WM_RBUTTONDBLCLK = 0x0206 ;right button
Global Const $WM_RBUTTONDOWN = 0x0204
Global Const $WM_RBUTTONUP = 0x0205
Global Const $WM_MBUTTONDBLCLK = 0x0209 ;wheel clicks
Global Const $WM_MBUTTONDOWN = 0x0207
Global Const $WM_MBUTTONUP = 0x0208
;Consts/structs from msdn
Global Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
;~ Global Const $WH_MOUSE_LL = 14 ;already declared
;~ Global Const $tagPOINT = "int X;int Y" ;already declared
;Create GUI
$GUI = GUICreate("Mouse Hook", 178, 158, @DesktopWidth-178, 0) ;Top-Left corner
$_Event = GUICtrlCreateLabel("Event: ", 8, 8, 158, 17)
$_XYpos = GUICtrlCreateLabel("X= Y=", 8, 32, 157, 17)
$_MData = GUICtrlCreateLabel("Mouse Data: ", 8, 56, 165, 17)
$_Flags = GUICtrlCreateLabel("Flags: ", 8, 80, 168, 17)
$_Timestamp = GUICtrlCreateLabel("Timestamp: ", 8, 104, 162, 17)
$_Extra = GUICtrlCreateLabel("Extra Info: ", 8, 128, 167, 17)
GUISetState()
WinSetOnTop($GUI, "", 1) ;make GUI stay on top of other windows
;Register callback
$hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)
While 1
If $GUI_EVENT_CLOSE = GUIGetMsg() Then Exit ;idle until exit is pressed
WEnd
Func _Mouse_Proc($nCode, $wParam, $lParam) ;function called for mouse events..
;define local vars
Local $info, $ptx, $pty, $mouseData, $flags, $time, $dwExtraInfo
Local $xevent = "Unknown", $xmouseData = ""
If $nCode < 0 Then ;recommended, see http://msdn.microsoft.com/en-us/library/ms644986(VS.85).aspx
$ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
"int", $nCode, "ptr", $wParam, "ptr", $lParam) ;recommended
Return $ret[0]
EndIf
$info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) ;used to get all data in the struct ($lParam is the ptr)
$ptx = DllStructGetData($info, 1) ;see notes below..
$pty = DllStructGetData($info, 2)
$mouseData = DllStructGetData($info, 3)
$flags = DllStructGetData($info, 4)
$time = DllStructGetData($info, 5)
$dwExtraInfo = DllStructGetData($info, 6)
; $ptx = Mouse x position
; $pty = Mouse y position
; $mouseData = can specify click states, and wheel directions
; $flags = Specifies the event-injected flag
; $time = Specifies the time stamp for this message
; $dwExtraInfo = Specifies extra information associated with the message.
;Find which event happened
Select
Case $wParam = $WM_MOUSEMOVE
$xevent = "Mouse Move"
Case $wParam = $WM_MOUSEWHEEL
$xevent = "Mouse Wheel"
If _WinAPI_HiWord($mouseData) > 0 Then
$xmouseData = "Wheel Forward"
Else
$xmouseData = "Wheel Backward"
EndIf
Case $wParam = $WM_LBUTTONDBLCLK
$xevent = "Double Left Click"
Case $wParam = $WM_LBUTTONDOWN
$xevent = "Left Down"
Case $wParam = $WM_LBUTTONUP
$xevent = "Left Up"
Case $wParam = $WM_RBUTTONDBLCLK
$xevent = "Double Right Click"
Case $wParam = $WM_RBUTTONDOWN
$xevent = "Right Down"
Case $wParam = $WM_RBUTTONUP
$xevent = "Right Up"
Case $wParam = $WM_MBUTTONDBLCLK
$xevent = "Double Wheel Click"
Case $wParam = $WM_MBUTTONDOWN
$xevent = "Wheel Down"
Case $wParam = $WM_MBUTTONUP
$xevent = "Wheel Up"
EndSelect
; Set GUI control data..
GUICtrlSetData($_Event, "Event: " & $xevent)
GUICtrlSetData($_XYpos, "X=" & $ptx & " Y=" & $pty)
If $xmouseData <> "" Then
GUICtrlSetData($_MData, "Mouse Data: " & $xmouseData)
Else
GUICtrlSetData($_MData, "Mouse Data: " & $mouseData)
EndIf
GUICtrlSetData($_Flags, "Flags: " & $flags)
GUICtrlSetData($_Timestamp, "Timestamp: " & $time)
GUICtrlSetData($_Extra, "Extra Info: " & $dwExtraInfo)
;This is recommended instead of Return 0
$ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _
"int", $nCode, "ptr", $wParam, "ptr", $lParam)
Return $ret[0]
EndFunc ;==>_Mouse_Proc
Func OnAutoItExit()
DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
$hM_Hook[0] = 0
DllCallbackFree($hKey_Proc)
$hKey_Proc = 0
EndFunc ;==>OnAutoItExit
Ok so i did a bit of research, and ended up with this
Code:
unc HookMe()
OnAutoItExitRegister("Cleanup")
Local $hMod = 0
$g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hMouseProc = DllCallbackRegister("_MouseProc", "int", "int;ptr;ptr")
$hMod = _WinAPI_GetModuleHandle(0)
$g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)
$g_hHookm = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseProc), $hMod)
EndFunc ;==>Example
Func _MouseProc($nCode, $wParam, $lParam)
Local $tMOUSEHOOKS
$tMOUSEHOOKS = DllStructCreate($MSLLHOOKSTRUCT, $lParam)
If Not ($nCode < 0) Then
If BitAND($tMOUSEHOOKS, $g_INJECTED_MASK) Then
$tMOUSEHOOKS.flags = BitAND(BitNOT($g_INJECTED_MASK), $tMOUSEHOOKS.flags)
EndIf
EndIf
Return _WinAPI_CallNextHookEx($g_hHookm, $nCode, $wParam, $lParam)
EndFunc ;==>_MouseProc
Func _KeyProc($nCode, $wParam, $lParam)
Local $tKEYHOOKS
$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If Not ($nCode < 0) Then
If BitAND($tKEYHOOKS.flags, $g_INJECTED_MASK) Then
$tKEYHOOKS.flags = BitAND(BitNOT($g_INJECTED_MASK), $tKEYHOOKS.flags)
EndIf
EndIf
Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc ;==>_KeyProc
Func Cleanup()
_WinAPI_UnhookWindowsHookEx($g_hHook)
_WinAPI_UnhookWindowsHookEx($g_hHookm)
DllCallbackFree($g_hStub_KeyProc)
DllCallbackFree($hMouseProc)
EndFunc ;==>Cleanup
^
This code (if i wrote it correctly should catch up events with LL_Injected flag
clean them and send forward using CallNextHookEx
Look like its working but :P
Mouse is acting weird due to delays.
Im not an AutoIt Vet if it comes to dllcalls and hooks like this one
I dont want to screw up anything.... so if theres anyone willing to help me, dm me and ill send u my discord tag in case of future questions






