Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 我如何让我的程序在;Q";自动按下按钮吗?_Loops_For Loop_Keyboard_Autoit_Terminate - Fatal编程技术网

Loops 我如何让我的程序在;Q";自动按下按钮吗?

Loops 我如何让我的程序在;Q";自动按下按钮吗?,loops,for-loop,keyboard,autoit,terminate,Loops,For Loop,Keyboard,Autoit,Terminate,我目前在AutoIt中设置了一个程序。以下是作为代码编写的内容,以及一些可能有助于回答我的问题的注释: ;File with data is pw.txt $fh = FileOpen("pw.txt") ;Loops 5 times, every time it loops $attempt should equal the next line of pw.txt For $i = 1 To 10 $attempt = FileReadLine($fh) MouseClick("left");

我目前在AutoIt中设置了一个程序。以下是作为代码编写的内容,以及一些可能有助于回答我的问题的注释:

;File with data is pw.txt
$fh = FileOpen("pw.txt")
;Loops 5 times, every time it loops $attempt should equal the next line of pw.txt
For $i = 1 To 10
$attempt = FileReadLine($fh)
MouseClick("left");MouseClick("left",711,256)
Sleep(700)
Send($attempt);Enters whatever is in $attempt variable
Sleep(700)
Send("{enter}")
Sleep(700)
MouseClick("left")
Sleep(700);Once first loop is finished, second loop begins. The only thing that is different is what is entered ($attempt)
Next
FileClose("pw.txt");After finished looping, file closes.
为了解决这个问题,我将循环计数设置为10,因此在$I=10(循环10次后)之后,程序仍将处于活动状态,但不会执行任何操作

我想这样做,如果用户点击键盘上的“Q”按钮,我的程序就会停止,不再执行进一步的操作(我不想完全关闭程序,只需停止循环)。最好,我希望下次运行程序时循环从1开始

例如,如果我在循环4上,我按下“Q”按钮,循环将停止,然后我应该能够单击“F5”按钮再次运行我的程序,它将在循环1上


任何帮助都将不胜感激!谢谢

您需要一个主循环,它允许您反复运行定时循环。您还需要运行和停止定时循环的功能,这些功能由热键调用:

HotKeySet('q', '_stopLoop')
HotKeySet('{F5}', '_runLoop')
HotKeySet('^!e', '_exit')    ; (Ctrl+Alt+e)   required to stop the main loop
Global $iLoopCounter

; start your loop now
_runLoop()


; you need a main loop
While True
    Sleep(10)
WEnd

Func _exit()
    Exit
EndFunc

Func _MyLoop()
    While $iLoopCounter < 10
        $iLoopCounter += 1
        ; your loop code here

        ;==================================== for demonstration
        ConsoleWrite('$iLoopCounter: ' & $iLoopCounter & @CRLF)
        Sleep(1000)
        ;======================================================

    WEnd
EndFunc

Func _runLoop()
    $iLoopCounter = 0
    _MyLoop()
EndFunc

Func _stopLoop()
    $iLoopCounter = 10
EndFunc
热键集('q','u stopLoop')
热键集(“{F5}”,“\u runLoop”)
热键集(“^!e”,“_exit”);(Ctrl+Alt+e)需要停止主循环
全局$iLoopCounter
; 现在开始你的循环
_runLoop()
; 你需要一个主回路
虽然是真的
睡眠(10)
温德
Func_exit()
出口
EndFunc
Func_MyLoop()
而$iLoopCounter<10
$iLoopCounter+=1
; 你的循环码在这里
;==================================== 示范
控制台写入(“$iLoopCounter:”&$iLoopCounter&@CRLF)
睡眠(1000)
;======================================================
温德
EndFunc
Func_runLoop()
$iLoopCounter=0
_MyLoop()
EndFunc
Func_stopLoop()
$iLoopCounter=10
EndFunc

查看热键集