找回密码
 加入
搜索
查看: 2108|回复: 1

[系统综合] 游戏辅助,鼠标钩子,PostMessage点击滞后一次,大牛请进

[复制链接]
发表于 2011-10-3 18:43:31 | 显示全部楼层 |阅读模式
我这里利用鼠标钩子 做了个游戏窗口同步鼠标的辅助
我很不解的是 为什么后台窗口总是落后激活窗口一次点击次数
就是说后台窗口每次执行的是我激活窗口前一次点击的位置
鼠标钩子部分代码如下,msgbox提示当前点击的窗口位置正确
不明白为何_WinAPI_PostMessage($hd,0x202,1,_MakeLong($Pos[0], $Pos[1]))
这句话会滞后一次执行,请各位高手指教,希望给出能够正确同步的方法。
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[0], $Pos[1]))
                        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[0], $Pos[1]))
                                _WinAPI_PostMessage($hd,0x201,1,_MakeLong($Pos[0], $Pos[1]))
                                        ;Sleep(10)
                                _WinAPI_PostMessage($hd,0x202,1,_MakeLong($Pos[0], $Pos[1]))
                                ;msgbox(0,$Pos[0], $Pos[1])
                                

                                ;MouseMove($Pos[0]+$size2[0] - $size1[0], $Pos[1]+$size2[1] - $size1[1],1)
                                ;ControlClick($hd,"","","left",1,$lPos[0], $lPos[1])
                        Next
                                ;MouseMove($Pos[0], $Pos[1],1)
        EndSwitch
        Return _WinAPI_CallNextHookEx($_whook, $wnCode, $wwParam, $wlParam) ;消息传递到下一个钩子
EndFunc
发表于 2011-10-15 23:53:10 | 显示全部楼层
沙发
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 23:40 , Processed in 0.084387 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表