如何通过在AHK中按“任意”键来中断循环?

时间:2013-12-02 15:49:09

标签: autohotkey

我目前有一个重复按下鼠标左键的脚本,直到脚本中断。要启动和停止脚本,请按ALT + 2。我如何从ALT + 2开始,但按任意键停止?

#MaxThreadsPerHotkey 3
!2::  ; ALT+2 hotkey 
#MaxThreadsPerHotkey 1
if KeepWinZRunning  
{
    KeepWinZRunning := false  ; 
    return  ; 
}

; Otherwise:
KeepWinZRunning := true
Loop
{
    ToolTip, Press ALT+2 again to stop.
    Sleep 100
    Send, {VK01 down}{VK01 up}
    Sleep 100
    if not KeepWinZRunning  

        break  ; Break out of this loop.

}
KeepWinZRunning := false  ; Reset in preparation for the next press of this hotkey.
ToolTip
return

ExitApp
F12::ExitApp

2 个答案:

答案 0 :(得分:4)

根据我的评论,以下是使用TimersInput的示例:

endKeys={enter}{tab}{LControl}{RControl}{LAlt}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}

!2::
    SetTimer, SendSomething, 200
    Input, pressedKey, I L1, % endKeys
    SetTimer, SendSomething, Off
return

SendSomething:
    Send, {VK01 down}{VK01 up}
return

您可能需要完成endkeys的列表,具体取决于您的键盘布局。

答案 1 :(得分:1)

拿一个look at this post。这是直接引用。您应该查看原始帖子以获取详细信息(我不能相信它),但这里是片段:

#InstallKeybdHook  ; this MUST be called at the start of your script

AnyKeyPressed() ; returns a 1 if any keyboard key is pressed, else returns 0
{
    if( A_TimeIdlePhysical < 25 )
        return 1

return 0
}