Reputation: 3
I'm trying to make an AutoHotkey script that holds Shift, and while it's holding it I need the mouse to click and release every second. This is what I have come up with so far.
Home::
KeyDown := !KeyDown
If KeyDown
SendInput {Shift down}, Click, Sleep 2000
Else
SendInput {Shift up}
Return
Upvotes: 0
Views: 2870
Reputation: 2344
This loop after a certain amount of time behavior is best implemented with a SetTimer function invoking a Subroutine.
Additionally, since your script holds down the Shift key, you would need to also have the hotkey be invoked whenever Shift+Home is pressed as well, so that it can be turned off.
Final Code:
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
Upvotes: 1