Global Const $WH_MOUSE_LL = 14
Global Const $WM_LBUTTONUP = 0x0202
#cs
https://docs.microsoft.com/zh-cn/previous-versions/windows/desktop/legacy/ms644986(v=vs.85)
LRESULT CALLBACK LowLevelMouseProc(
_In_ int nCode,
_In_ WPARAM wParam,
_In_ LPARAM lParam
);
#ce
Local $hCallback = DllCallbackRegister("_LowLevelMouseProc", "int", "int;WPARAM;LPARAM")
Local $hModule = _WinAPI_GetModuleHandle(0)
;安装一个钩子程序, 监控鼠标消息
Local $hHook = DllCall("user32.dll", "handle", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hCallback), "handle", $hModule, "dword", 0)
OnAutoItExitRegister("_Clean")
While 1
Sleep(10)
WEnd
Func _LowLevelMouseProc($nCode, $wParam, $lParam)
If $nCode < 0 Then Return DllCall("user32.dll", "lresult", "CallNextHookEx", "handle", $hHook, "int", $nCode, "wparam", $wParam, "lparam", $lParam)
Switch $wParam
Case $WM_LBUTTONUP;鼠标左键抬起
Send("^c")
EndSwitch
Return DllCall("user32.dll", "lresult", "CallNextHookEx", "handle", 0, "int", $nCode, "wparam", $wParam, "lparam", $lParam)
EndFunc ;==>_LowLevelMouseProc
Func _Clean()
DllCall("user32.dll", "bool", "UnhookWindowsHookEx", "handle", $hHook)
DllCallbackFree($hCallback)
EndFunc
Func _WinAPI_GetModuleHandle($sModuleName)
Local $sModuleNameType = "wstr"
If $sModuleName = "" Then
$sModuleName = 0
$sModuleNameType = "ptr"
EndIf
Local $aResult = DllCall("kernel32.dll", "handle", "GetModuleHandleW", $sModuleNameType, $sModuleName)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[0]
EndFunc ;==>_WinAPI_GetModuleHandle
2.遇到的问题