找回密码
 加入
搜索
查看: 2218|回复: 9

[AU3基础] [已解决]热键停止循环中的脚本

  [复制链接]
发表于 2017-4-21 05:03:35 | 显示全部楼层 |阅读模式
本帖最后由 3131210 于 2017-4-22 02:16 编辑

这个脚本可以按F7或者点开始 启动     点停止就停止    怎么设置按F8停止呢?
#include <GUIConstants.au3>

$Exists = "网站测试工具";判断是否只运行一个程序
If WinExists($Exists) Then
        MsgBox(32,"温馨提醒:","注意已经运行一个程序了!")
        Exit
EndIf
AutoItWinSetTitle($Exists);修改程序窗口的标题名
$Reate0 = GUICreate($Exists, 200, 150, 350, 400);主窗口
$Web = GUICtrlCreateButton("浏览", 120, 25, 70, 20);浏览按钮
$Start = GUICtrlCreateButton("开始(F7)", 120, 119, 70, 20);开始按钮
$Stop = GUICtrlCreateButton("停止(F8)", 120, 69, 70, 20);停止按钮
GUICtrlCreateLabel ("浏览器路径",  10, 6, 120)
GUICtrlCreateLabel ("首个网站打开等待时间",  10, 50, 120)
GUICtrlCreateLabel ("其余网站打开等待时间",  10, 100, 120)
GUICtrlCreateLabel ("单位:毫秒",  55, 72, 60)
GUICtrlCreateLabel ("单位:毫秒",  55, 122, 60)
$first = GUICtrlCreateInput ( "2000", 10, 70 , 40, 18, $ES_CENTER)
$delay = GUICtrlCreateInput ( "200", 10, 120 , 40, 18, $ES_CENTER)
$address = GUICtrlCreateInput ( "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --incognito", 10,  24, 100, 20)
GUISetState(@SW_SHOW)
HotKeySet("{F7}",test)

While 1
   $Tray = TrayGetMsg();得到一个系统托盘图标项目产生的事件.
   $nMsg = GUIGetMsg()
   Switch $nMsg
          Case $Web
                 $var = FileOpenDialog('选择浏览器', 'C:\', "程序 (*.exe)", 1)
                 If Not @error Then
                        GUICtrlSetData($address, $var)
                 EndIf
          Case $Start
                 test()
          Case $GUI_EVENT_CLOSE
                 Exit
   EndSwitch
WEnd

Func test()
   $file = FileOpen("网站地址.txt", 0)
   If $file = -1 Then
          MsgBox(0, "错误", '找不到“网站地址.txt”文件,请确认文件目录下是否存在该文件。')
   Else
          $i = 1
          While 1
          $line = FileReadLine($file,$i)
          $wz = GUICtrlRead($address) & " " & $line
                 If $Line = "" Then ExitLoop
                 If @error = -1 Then ExitLoop
                 Run($wz)
                 If $i = 1 Then
                        Sleep(GUICtrlRead($first))
                 Else
                        Sleep(GUICtrlRead($delay))
                 EndIf
                 $choice = GUIGetMsg()
                 If $choice = $Stop Then
                        ExitLoop
                 EndIf
                 $i = $i + 1
          Wend
          FileClose($file)
   EndIf
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-4-21 08:42:35 | 显示全部楼层
au3是单进程的。。你按下开始后,其他按钮是无反应了,只能靠注册hotkey来达到停止的目的。。好像是这样的。。楼下你说说看
发表于 2017-4-21 10:33:55 | 显示全部楼层
这个脚本可以按F7或者点开始 启动     点停止就停止    怎么设置按F8停止呢?
3131210 发表于 2017-4-21 05:03


HotKeySet("{F7}",test)
HotKeySet("{F8}",Tinz)
-------省略---------

Func Tinz()
        MsgBox(0, "", '停止')
EndFunc
发表于 2017-4-21 12:24:51 | 显示全部楼层
用一个变量来代表执行或停止的标志就行了.

$bStop = true 停止
$bStip = false 继续循环.

响应热键的函数中,改变此值.
 楼主| 发表于 2017-4-21 13:50:44 | 显示全部楼层
代码改成下面这样        $ts=1  确实是生效了   但是 if $ts=1 then exitloop 就是停不下来
#include <GUIConstants.au3>

$Exists = "网站测试工具";判断是否只运行一个程序
If WinExists($Exists) Then
        MsgBox(32,"温馨提醒:","注意已经运行一个程序了!")
        Exit
EndIf
AutoItWinSetTitle($Exists);修改程序窗口的标题名
$Reate0 = GUICreate($Exists, 200, 150, 350, 400);主窗口
$Web = GUICtrlCreateButton("浏览", 120, 25, 70, 20);浏览按钮
$Start = GUICtrlCreateButton("开始(F7)", 120, 119, 70, 20);开始按钮
$Stop = GUICtrlCreateButton("停止(F8)", 120, 69, 70, 20);停止按钮
GUICtrlCreateLabel ("浏览器路径",  10, 6, 120)
GUICtrlCreateLabel ("首个网站打开等待时间",  10, 50, 120)
GUICtrlCreateLabel ("其余网站打开等待时间",  10, 100, 120)
GUICtrlCreateLabel ("单位:毫秒",  55, 72, 60)
GUICtrlCreateLabel ("单位:毫秒",  55, 122, 60)
$first = GUICtrlCreateInput ( "2000", 10, 70 , 40, 18, $ES_CENTER)
$delay = GUICtrlCreateInput ( "200", 10, 120 , 40, 18, $ES_CENTER)
$address = GUICtrlCreateInput ( "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --incognito", 10,  24, 100, 20)
GUISetState(@SW_SHOW)
HotKeySet("{F7}",test)

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
          Case $Web
                 $var = FileOpenDialog('选择浏览器', 'C:\', "程序 (*.exe)", 1)
                 If Not @error Then
                        GUICtrlSetData($address, $var)
                 EndIf
          Case $Start
                 test()
          Case $GUI_EVENT_CLOSE
                 Exit
   EndSwitch
WEnd

Func test()
   $ts = 0
   $file = FileOpen("网站地址.txt", 0)
   If $file = -1 Then
          MsgBox(0, "错误", '找不到“网站地址.txt”文件,请确认文件目录下是否存在该文件。')
   Else
          $i = 1
          While 1
                 $line = FileReadLine($file,$i)
                 HotKeySet("{F8}",teststop)
                 $wz = GUICtrlRead($address) & " " & $line
                 If $Line = "" Then ExitLoop
                 If @error = -1 Then ExitLoop
                 If $ts = 1 Then ExitLoop
                 Run($wz)
                 If $i = 1 Then
                        Sleep(GUICtrlRead($first))
                 Else
                        Sleep(GUICtrlRead($delay))
                 EndIf
                 $choice = GUIGetMsg()
                 If $choice = $Stop Then ExitLoop
                 $i = $i + 1
          Wend
          FileClose($file)
   EndIf
EndFunc

Func teststop()
   $ts = 1
EndFunc
发表于 2017-4-21 14:44:18 | 显示全部楼层
回复 5# 3131210

HotKeySet("{F8}",teststop)
要在HotKeySet("{F7}",test)下面第23行,
第52行可以删除
 楼主| 发表于 2017-4-22 00:51:53 | 显示全部楼层
回复 6# chzj589


    亲,按你说的,也是不停的哦。
 楼主| 发表于 2017-4-22 02:08:38 | 显示全部楼层
解决了   成品
#include <GUIConstants.au3>

$Exists = "网站测试工具";判断是否只运行一个程序
If WinExists($Exists) Then
        MsgBox(32,"温馨提醒:","注意已经运行一个程序了!")
        Exit
EndIf
AutoItWinSetTitle($Exists);修改程序窗口的标题名
$Reate0 = GUICreate($Exists, 200, 150, 350, 400);主窗口
$Web = GUICtrlCreateButton("浏览", 120, 25, 70, 20);浏览按钮
$Start = GUICtrlCreateButton("开始(F7)", 120, 119, 70, 20);开始按钮
$Stop = GUICtrlCreateButton("停止(F8)", 120, 69, 70, 20);停止按钮
GUICtrlCreateLabel ("浏览器路径",  10, 6, 60)
GUICtrlCreateLabel ("首个网站打开等待时间",  10, 50, 120)
GUICtrlCreateLabel ("其余网站打开等待时间",  10, 100, 120)
GUICtrlCreateLabel ("单位:毫秒",  55, 72, 60)
GUICtrlCreateLabel ("单位:毫秒",  55, 122, 60)
$first = GUICtrlCreateInput ( "2000", 10, 70 , 40, 18, $ES_CENTER)
$delay = GUICtrlCreateInput ( "200", 10, 120 , 40, 18, $ES_CENTER)
$address = GUICtrlCreateInput ( "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --incognito", 10,  24, 100, 20)
$Fix = GUICtrlCreateCheckbox("自动修正网址", 100, 4, 90, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetState(@SW_SHOW)
HotKeySet("{F7}",test)

While 1
   $msg = GUIGetMsg()
   Switch $msg
          Case $Web
                 $var = FileOpenDialog('选择浏览器', 'C:\', "程序 (*.exe)", 1)
                 If Not @error Then GUICtrlSetData($address, $var)
          Case $Start
                 test()
          Case $GUI_EVENT_CLOSE
                 Exit
   EndSwitch
WEnd

Func test()
   HotKeySet("{F8}",teststop)
   $file = FileOpen("网站地址.txt", 0)
   If $file = -1 Then
          MsgBox(0, "错误", '找不到“网站地址.txt”文件,请确认文件目录下是否存在该文件。')
   Else
          $i = 1
          Global $ts = 0
          While 1
                 Switch $ts
                        Case 0
                           $line = FileReadLine($file,$i)
                           If GUICtrlRead($Fix) = 1 Then
                                  Local $line1 = StringRegExpReplace($line, '(http|https):\/\/', "")
                           Else
                                  $line1 = $line
                           EndIf
                           $wz = GUICtrlRead($address) & " " & $line1
                           If $Line1 = "" Then ExitLoop
                           If @error = -1 Then ExitLoop
                           Run($wz)
                           If $i = 1 Then
                                  Sleep(GUICtrlRead($first))
                           Else
                                  Sleep(GUICtrlRead($delay))
                           EndIf
                           $choice = GUIGetMsg()
                           If $choice = $Stop Then ExitLoop
                           $i = $i + 1
                        Case 1
                           ExitLoop
                 EndSwitch
          Wend
          FileClose($file)
   EndIf
EndFunc

Func teststop()
   $ts = 1
EndFunc
发表于 2017-4-22 02:22:11 | 显示全部楼层
回复 7# 3131210

這樣不就可以了  點擊 開始     然後 F8 停  然後可以再度點擊開始  在按 F8 停

#include <GUIConstants.au3>

$Exists = "网站??工具";判?是否只?行一?程序
If WinExists($Exists) Then
        MsgBox(32,"?馨提醒:","注意已??行一?程序了!")
        Exit
EndIf
AutoItWinSetTitle($Exists);修改程序窗口的??名
$Reate0 = GUICreate($Exists, 200, 150, 350, 400);主窗口
$Web = GUICtrlCreateButton("??", 120, 25, 70, 20);??按?
$Start = GUICtrlCreateButton("?始(F7)", 120, 119, 70, 20);?始按?
$Stop = GUICtrlCreateButton("停止(F8)", 120, 69, 70, 20);停止按?
GUICtrlCreateLabel ("??器路?",  10, 6, 120)
GUICtrlCreateLabel ("首?网站打?等待??",  10, 50, 120)
GUICtrlCreateLabel ("其余网站打?等待??",  10, 100, 120)
GUICtrlCreateLabel ("?位:毫秒",  55, 72, 60)
GUICtrlCreateLabel ("?位:毫秒",  55, 122, 60)
$first = GUICtrlCreateInput ( "2000", 10, 70 , 40, 18 )
$delay = GUICtrlCreateInput ( "200", 10, 120 , 40, 18)
$address = GUICtrlCreateInput ( "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --incognito", 10,  24, 100, 20)
GUISetState(@SW_SHOW)
HotKeySet("{F7}","test")
HotKeySet("{F8}","teststop")
 $ts = 0
 
While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
          Case $Web
                 $var = FileOpenDialog('????器', 'C:\', "程序 (*.exe)", 1)
                 If Not @error Then
                        GUICtrlSetData($address, $var)
                 EndIf
          Case $Start
                 test()
          Case $GUI_EVENT_CLOSE
                 Exit
   EndSwitch
WEnd

Func test()
  
        If $ts = 1 THEN  $ts = 0
   $i = 1
     While 1
                 
                 
                                         $i = $i + 1
                        ConsoleWrite($ts&" "&$i&@CRLF)
                        If $ts = 1 Then ExitLoop
                SLEEP(10)
          Wend

EndFunc

Func teststop()
   $ts = 1
EndFunc
 楼主| 发表于 2017-4-23 11:38:58 | 显示全部楼层
回复 9# kk_lee69


    好用 谢谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-20 01:37 , Processed in 0.081375 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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