[已解决]如何实时获取鼠标当前坐标?
本帖最后由 3131210 于 2018-3-17 21:33 编辑想要实时获取当前鼠标坐标,为什么下面得代码获取不到坐标?#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
GUIRegisterMsg($WM_MOUSEMOVE, 'WM_MOUSEMOVE')
Example()
Func Example()
While 1
WEnd
EndFunc ;==>Example
Func WM_MOUSEMOVE($hWnd, $iMsg, $wParam, $lParam)
Local $aPos = MouseGetPos()
Local $iX = $aPos
Local $iY = $aPos
ConsoleWrite($iX & '/' & $iY & @CRLF)
EndFunc ;==>WM_MOUSEMOVE
这段代码在鼠标静止的情况下也会获取坐标,但是我只想在鼠标动的时候才获取。Example()
Func Example()
While Sleep(10)
Local $aPos = MouseGetPos()
Local $iX = $aPos
Local $iY = $aPos
ConsoleWrite($iX & '/' & $iY & @CRLF)
WEnd
EndFunc ;==>Example Example()
Func Example()
Local $sIntX = MouseGetPos(0)
Local $sIntY = MouseGetPos(1)
While Sleep(10)
Local $aPos = MouseGetPos()
Local $iX = $aPos
Local $iY = $aPos
If $iX <> $sIntX Or $iY <> $sIntY Then
$sIntX = $iX
$sIntY = $iY
ConsoleWrite($iX & '/' & $iY & @CRLF)
EndIf
WEnd
EndFunc 本帖最后由 3131210 于 2018-3-17 20:54 编辑
回复 3# zghwelcome
你的办法实际上也是一直在获取鼠标坐标,只是加了个判断与之前的坐标是否一致
可以用1楼钩子的方法实现吗? #include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $_whand = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
Local $_whmod = _WinAPI_GetModuleHandle(0)
Global $_whook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($_whand), $_whmod)
While 1
Sleep(10)
WEnd
Func _Mouse_Events_Handler($wnCode, $wwParam, $wlParam)
Switch $wwParam
Case $WM_MOUSEMOVE ;鼠标移动
Local $aPos = MouseGetPos()
Local $iX = $aPos
Local $iY = $aPos
ConsoleWrite($iX & '/' & $iY & @CRLF)
EndSwitch
EndFunc ;==>_Mouse_Events_Handler
页:
[1]