本帖最后由 caodongchun 于 2009-7-18 15:07 编辑
你这段代码停止=退出,加入AdlibEnable即可!
如果某些函数还在进行中,要终止他,只能使用比他优先级更高的函数,比如热键,TrayOnEventMode,AdlibEnable 均可达到你的要求,下面的实例就是用了AdlibEnable,感觉上好像是gui循环模式生效,而实际是AdlibEnable检测起到了作用!
#include <GUIConstants.au3>
HotKeySet("{F2}", "ExitProgram")
#Region ### START Koda GUI section ### Form=
$AForm1 = GUICreate("AForm1", 206, 83, 780, 16)
$Label1 = GUICtrlCreateLabel("次数:", 18, 20, 44, 17)
$Input1 = GUICtrlCreateInput("5", 56, 16, 57, 21)
$Button1 = GUICtrlCreateButton("开始", 120, 14, 67, 25, 0)
$Button2 = GUICtrlCreateButton("停止", 120, 48, 67, 25, 0)
GUISetState(@SW_SHOW)
AdlibEnable('stop',20)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Run('NOTEPAD.exe')
Sleep(500)
kaishi()
Case $Button2
ExitLoop
EndSwitch
WEnd
Func stop()
If GUIGetMsg() = $Button2 Then Exit
EndFunc
Func kaishi()
For $x = 1 to (GUICtrlRead($Input1))
Dim $Num = ""
For $i = 1 To 4
$Num = $Num & Chr(Random(Asc("0"), Asc("z"), 1)) ;Random(97, 122, 1) 也可替换为 Random(Asc("a"), Asc("z"), 1)
Next
WinActivate("无标题 - 记事本")
send($Num)
Sleep(600)
send("{enter}")
Next
EndFunc
Exit
Func ExitProgram()
Exit
EndFunc
|