【问题标题】:AutoIt termination HotKeySet not workingAutoIt 终止 HotKeySet 不起作用
【发布时间】:2013-11-06 05:08:04
【问题描述】:

非常简单明了,我正在尝试使用 ESC 键终止脚本,并且在运行 Path() 时它不会终止。我尝试将 HotKeySet 定义放在 Path() 函数中,但仍然没有用。我是 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 

【问题讨论】:

    标签: path autoit hotkeys


    【解决方案1】:

    我猜是因为您发送的是大写字母。这导致移位保持 500 毫秒。您必须在此期间按 shift ESC 或设置另一个热键,如下所示:

    ; 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      相关资源
      最近更新 更多