Reputation: 1195
I have a simple script that doesn't seem to behave as expected:
^j::
Send, {Down down}
Sleep, 10000
Send, {Down up}
Return
I would like it to hold the down arrow key for 10 seconds, and then release. Instead, it presses the down key once, and breaks the script until reload. What am I doing wrong?
Upvotes: 1
Views: 7200
Reputation: 1205
Found a nice workaround, try some script like this (adjust the Mynumber variable to your liking and the Sleep aswell)
a::
Mynumber = 10
While Mynumber > 0
{
Send {Down DOWN}
Sleep 10
Send {Down UP}
Mynumber--
}
Upvotes: 1
Reputation: 73806
Send
documentation says:
When a key is held down via the method above, it does not begin auto-repeating like it would if you were physically holding it down (this is because auto-repeat is a driver/hardware feature).
Use SetKeyDelay and specify the number of repetitions:
SetKeyDelay, 30
Send {Down 333}
333
is approximately 10000/30
Alternatively you can do it in a loop
and check for other keys in order to stop sending Down
key.
Upvotes: 1
Reputation: 1205
According to documentation this should work:
To hold down or release a key: Enclose in braces the name of the key followed by the word Down or Up. For example:
Send {b down}{b up}
Send {TAB down}{TAB up}
Send {Up down} ; Press down the up-arrow key.
Sleep 1000 ; Keep it down for one second.
Send {Up up} ; Release the up-arrow key.
docs about holding down keys: https://www.autohotkey.com/docs/commands/Send.htm
Upvotes: 0