Question

Pretty plain and simple, I'm trying to terminate the script with the ESC key and it won't terminate when running Path(). I've tried putting the HotKeySet definitions in the Path()function and still didn't work. I'm new to AutoIt.

; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
; Start Pathing
MsgBox(0,"Starting...","Will Start 2 seconds after you close this.")
Sleep(2000)
Path()


Func Path()
   Opt("SendKeyDownDelay", 500)
   $pathing = True
   $i = 0
   $j = 5 ; Only here to prevent an infinite loop because HotKeySet won't terminate on ESC
   While $i < $j
      Send("{A}")
      Send("{S}")
      Send("{W}")
      Send("{D}")
      $i = $i + 1
   WEnd
EndFunc

Func CheckForBattle()
   Return True
EndFunc

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   

Func Terminate()
    Exit 0
EndFunc  

Func ShowMessage()
    MsgBox(4096, "", "This is a message.")
EndFunc 
Était-ce utile?

La solution

I guess it is because you are sending capital letters. This leads to shift is held for 500ms. You have to either press shift ESC during that time or set another hotkey like this:

; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+{ESC}", "Terminate")
; Start Pathing
MsgBox(0, "Starting...", "Will Start 2 seconds after you close this.")
Sleep(2000)
Path()

Func Path()
    Opt("SendKeyDownDelay", 500)
    $pathing = True
    $i = 0
    $j = 5 ; Only here to prevent an infinite loop because HotKeySet won't terminate on ESC
    While $i < $j
        Send("A")
        Send("S")
        Send("W")
        Send("D")
        $i = $i + 1
    WEnd
EndFunc   ;==>Path

Func CheckForBattle()
    Return True
EndFunc   ;==>CheckForBattle

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func ShowMessage()
    MsgBox(4096, "", "This is a message.")
EndFunc   ;==>ShowMessage
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top