Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send a key multiple times in Autohotkey?

Tags:

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?

like image 669
Stevoisiak Avatar asked Aug 16 '17 14:08

Stevoisiak


People also ask

Can AutoHotkey record keystrokes?

AutoHotkey definitely does not have built-in recording capabilities--you would need to use a third party macro recorder if you don't want to just code the macro from scratch.


2 Answers

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 
like image 50
Stevoisiak Avatar answered Sep 28 '22 18:09

Stevoisiak


If you want the repeat in a loop, let's say every 3 seconds:

#a::   ; Win+a Loop, 10 {     SendInput {Tab}     Sleep, 3000 } 
like image 43
Avatar Avatar answered Sep 28 '22 20:09

Avatar