sha66 发表于 2011-10-3 18:43:31

游戏辅助,鼠标钩子,PostMessage点击滞后一次,大牛请进

我这里利用鼠标钩子 做了个游戏窗口同步鼠标的辅助
我很不解的是 为什么后台窗口总是落后激活窗口一次点击次数
就是说后台窗口每次执行的是我激活窗口前一次点击的位置
鼠标钩子部分代码如下,msgbox提示当前点击的窗口位置正确
不明白为何_WinAPI_PostMessage($hd,0x202,1,_MakeLong($Pos, $Pos))
这句话会滞后一次执行,请各位高手指教,希望给出能够正确同步的方法。
Func _Main()
        $_whand = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
        $hmod = _WinAPI_GetModuleHandle(0)
        $_whook=_WinAPI_SetWindowsHookEx($WH_MOUSE_LL,DllCallbackGetPtr($_whand),$hmod)
        While 1
                Sleep(10)
        WEnd
EndFunc

Func _Mouse_Events_Handler($wnCode, $wwParam, $wlParam)
        Local $Pos,$activeh,$size1,$size2,$lPos
        Local $F = False
        If $flag = False Then Return

        Opt("MouseCoordMode", 2)

        Switch $wwParam
                Case $WM_LBUTTONUP   ;按下鼠标左键

                        If $wnCode < 0 Then
                                        Return _WinAPI_CallNextHookEx($_whook, $wnCode, $wwParam, $wlParam) ;消息传递到下一个钩子
                        EndIf

                        $activeh = _My_WinAPI_GetForegroundWindow()
                        For $hd In $hand
                                If $hd == $activeh Then $F = True
                        Next
                        If $F = False Then Return
                       
                        $size1 = WinGetPos($activeh)
                        If UBound($size1) < 2 Then Return
                        $Pos = MouseGetPos()
                        _WinAPI_PostMessage($activeh,0x202,1,_MakeLong($Pos, $Pos))
                        For $hd In $hand
                                If $hd == $activeh Then ContinueLoop
                                If $_ControlHandle <> "" Then
                                        $hd = ControlGetHandle($hd, "", $_ControlHandle)
                                EndIf
                               
                                $size2 = WinGetPos($hd)
                                _WinAPI_PostMessage($hd,0x200,1,_MakeLong($Pos, $Pos))
                                _WinAPI_PostMessage($hd,0x201,1,_MakeLong($Pos, $Pos))
                                        ;Sleep(10)
                                _WinAPI_PostMessage($hd,0x202,1,_MakeLong($Pos, $Pos))
                                ;msgbox(0,$Pos, $Pos)
                               

                                ;MouseMove($Pos+$size2 - $size1, $Pos+$size2 - $size1,1)
                                ;ControlClick($hd,"","","left",1,$lPos, $lPos)
                        Next
                                ;MouseMove($Pos, $Pos,1)
        EndSwitch
        Return _WinAPI_CallNextHookEx($_whook, $wnCode, $wwParam, $wlParam) ;消息传递到下一个钩子
EndFunc

魔导 发表于 2011-10-15 23:53:10

沙发{:1_498:}
页: [1]
查看完整版本: 游戏辅助,鼠标钩子,PostMessage点击滞后一次,大牛请进