找回密码
 加入
搜索
查看: 2061|回复: 2

[AU3基础] 这个程序如何退出才好?

[复制链接]
发表于 2012-2-11 19:49:15 | 显示全部楼层 |阅读模式
这是一个很简单发送无限按键的程序,但是我每次强制退出的后,游戏一直会受到最后一个按键影响很长一段时间。(比如强制退出前的最后一次按键是“下”,那么游戏程序就一直受到“下”的命令,过了很久才恢复)。

不知有啥解决办法~~?

#Include <PostMessage_UDF.au3>
$i=1
$key=0
While 1
        $hWnd=WinGetHandle("NO$Zoomer")
        ;MsgBox(0,"a",$i)
        If $i = 1 Then
                takeStep($hWnd, "right")
        ElseIf $i = 2 Then
                takeStep($hWnd, "up")
        ElseIf $i = 3 Then
                takeStep($hWnd, "left")
        ElseIf $i = 4 Then
                takeStep($hWnd, "down")
                ;MsgBox(0,"zzzzzzzzzzzzz","")
                $i=0
        EndIf
        ;MsgBox(0,"c",$i)
        $i = $i + 1
        ;MsgBox(0,"b",$i)
WEnd

Func takeStep($hWnd,$key)
        $j=100
        While $j > 0
                _ArrowKey($hWnd, $key)
                $j=$j-1
        WEnd
EndFunc
发表于 2012-2-11 20:19:48 | 显示全部楼层
#include <PostMessage_UDF.au3>

HotKeySet('{Esc}', '_ExitLoop')

Local $i = 1, $key = 0, $FExit = 0, $hWnd
$hWnd = WinGetHandle("NO$Zoomer")

While IsHWnd($hWnd) And Not $FExit
        Sleep(1)
        If $i = 1 Then
                takeStep($hWnd, "right")
        ElseIf $i = 2 Then
                takeStep($hWnd, "up")
        ElseIf $i = 3 Then
                takeStep($hWnd, "left")
        ElseIf $i = 4 Then
                takeStep($hWnd, "down")
                $i = 0
        EndIf
        $i += 1
WEnd
MsgBox(64, 'ok', '已退出 ')

Func takeStep($hWnd, $key)
        $j = 100
        While $j > 0 And Not $FExit
                _ArrowKey($hWnd, $key)
                $j -= 1
                Sleep(1)
        WEnd
EndFunc   ;==>takeStep

Func _ExitLoop()
        $FExit = 1
EndFunc   ;==>_ExitLoop
发表于 2012-2-12 10:49:22 | 显示全部楼层
学习了!!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-20 19:44 , Processed in 0.073334 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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