Jump to content

How to continue loop with a hotkey


leuce
 Share

Recommended Posts

Hello everyone

I need to write a script that runs a For...Next loop during which the script will sometimes take too long to go to the next iteration, and I want the user to have the ability to press a hotkey to force the script to continue the loop immediately.  FWIW, during each loop, the script will wait for the clipboard to change, but sometimes the clipboard isn't going to change and yet the user would want to move on to the next iteration.

Obviously, this doesn't work: 🙂

HotKeySet("{SPACE}", "GoOn")

While 1
Sleep (100)
WEnd

For $i = 1 to 10
[[some actions here]]
Next

Func GoOn()
ContinueLoop
EndFunc

Do you have any advice for me?  How can I set a hotkey (e.g. spacebar) which will cause a For...Next loop to continue the loop?

Thanks

Samuel

Edited by leuce
Link to comment
Share on other sites

a possible way

Global $bContinueLoop

HotKeySet("{SPACE}", "GoOn")

$sClipGet = ClipGet() ; initial peek of clipboard

For $i = 1 To 10
    Do ; wait for clipboard to change (or a forced iteration)
        Sleep(250)
    Until ($sClipGet <> ClipGet()) Or $bContinueLoop

    $sClipGet = ClipGet() ; put the new clipboard content to the $sClipGet variable

    If $bContinueLoop Then
        ConsoleWrite("iteration " & $i & " has been forced" & @CRLF)
        $bContinueLoop = False
    Else
        ConsoleWrite("iteration " & $i & " Clipboard has changed" & @CRLF)
    EndIf
Next

Func GoOn()
    $bContinueLoop = True
EndFunc   ;==>GoOn

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...