1
votes

This script is suppose to start/stop when a key is pressed. I want that to be the same key. Example I press F3 to start and I press F3 again to stop it. It will slowly count from 0000 to 9999 and will remember where you are when you stop the loop. For some reason it will start but when I press F3 again it doesn't stop. Followed this example http://www.autohotkey.com/docs/FAQ.htm#repeat What am I doing wrong?

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

start = 0000
Run = false

F3::                       
SetFormat, Float, 04.0
current = %start%

if Run {
    Run := false
    return 
}

Run := true
Loop, 9999{
    Send e                      
    Sleep, 760 

    TrayTip, PinCode BruteForce, %current%, , 16
    Send %current%                  
    current += 1.0
    start += 1.0
    Sleep, 700

    if(current = 10000){
        Break
    }

    if (not Run){
        Break
    }
}

Run := false
return
1

1 Answers

1
votes

You're missing the #MaxThreadsPerHotkey which can be found at the very link you posted. Its default value is 1, so once you pressed F3, it can't be fired again. Increase it, so the hotkey can interrupt itself the way you want it to.

Here are three other ways to stop an action from executing:

  • using a timer instead of a loop and toggling its state
  • using the pause command
  • using the goto command