Reputation: 26742
I want to write an AutoHotkey script which presses a key X number of times. For example, here's a script which presses Tab 10 times.
Send, {Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}{Tab}
While the above solution works, it's a bit unwieldy.
Is there a better solution for sending a key multiple times?
Upvotes: 27
Views: 64325
Reputation: 15156
If you want the repeat in a loop, let's say every 3 seconds:
#a:: ; Win+a
Loop, 10
{
SendInput {Tab}
Sleep, 3000
}
Upvotes: 9
Reputation: 26742
Try using Send {Tab 10}
Repeating or Holding Down a Key
To repeat a keystroke: Enclose in braces the name of the key followed by the number of times to repeat it. For example:
Send {DEL 4} ; Presses the Delete key 4 times. Send {S 30} ; Sends 30 uppercase S characters. Send +{TAB 4} ; Presses Shift-Tab 4 times.
Source: AutoHotkey - Send / SendRaw / SendInput / SendPlay / SendEvent: Send Keys & Clicks
This also works with ControlSend and ControlSendRaw
ControlSend, Edit1, {Enter 5}, Untitled - Notepad
Upvotes: 54