Autohotkey 如何通过按“中断”来中断循环;任何;输入AHK?
我目前有一个脚本,它反复按下鼠标左键,直到脚本被中断。要启动和停止脚本,请按ALT+2。如何让它以ALT+2开始,但按任意键停止Autohotkey 如何通过按“中断”来中断循环;任何;输入AHK?,autohotkey,Autohotkey,我目前有一个脚本,它反复按下鼠标左键,直到脚本被中断。要启动和停止脚本,请按ALT+2。如何让它以ALT+2开始,但按任意键停止 #MaxThreadsPerHotkey 3 !2:: ; ALT+2 hotkey #MaxThreadsPerHotkey 1 if KeepWinZRunning { KeepWinZRunning := false ; return ; } ; Otherwise: KeepWinZRunning := true Loop {
#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
坐一会儿。这是直接引述。您应该查看原始帖子以了解详细信息(我不认为这是值得称赞的),但以下是片段:
#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
}
#InstallKeybdHook;这必须在脚本开始时调用
按任意键();如果按下任何键盘键,则返回1,否则返回0
{
if(A_TimeIdlePhysical<25)
返回1
返回0
}
根据我的评论,下面是一个使用定时器和输入的示例:
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
根据您的键盘布局,您可能必须完成结束键列表。在大多数情况下,这不起作用A_TimeIdlePhysical
也会被鼠标事件重置。因此,只要移动鼠标,循环就会停止;而且不仅仅是在按下一个键的时候。@MCL-那么,你是说keybdhook将鼠标视为键盘键吗?@MCL a#u TimeIdlePhysical不会被重置,因为#InstallKeybdHook
你们都完全正确。我从来不知道,如果只安装了一个钩子,那么只有它的物理输入类型会影响一个\u TimeIdlePhysical。1)使用它们而不是无限循环,它们为(伪)多线程提供了更好的支持。2) 这就是你要找的。不过,请仔细查看选项。MCL是正确的。计时器还提供同时运行线程甚至中断计时器线程的选项。MCL以前帮过我。