Autohotkey,切换:按住 Shift,每秒单击并释放按钮

Auto HotKey, Toggle: Hold Shift, Click and release LButton every second

我正在尝试制作一个包含 Shift 的 AutoHotkey 脚本,当它包含它时,我需要鼠标每秒单击并释放一次。这是我到目前为止想出的。

Home::
KeyDown := !KeyDown
If KeyDown
    SendInput {Shift down}, Click, Sleep 2000
Else
    SendInput {Shift up}
Return

这种在一定时间后循环的行为最好用 SetTimer function invoking a Subroutine 来实现。

此外,由于您的脚本按住 Shift 键,因此您还需要在 Shift+Home也按下了,这样就可以关机了。


最终代码:

Home::
+Home:: ;Alternative hotkey definition that invokes on Shift+Home
    KeyDown := !KeyDown
    if (KeyDown){
        SendInput {Shift down}
        gosub, clickSubroutine ;To trigger the first click immediately
        SetTimer, clickSubroutine, 1000 ;To trigger clicks after every 1000 ms (1 second)
    }
    else{
        SendInput {Shift up}
        SetTimer, clickSubroutine, Off ;Turn off the clickSubroutine Loop
    }
Return

clickSubroutine:
    Click
return