Supa
Supa

Reputation: 145

How would I set a key delay between each sent character in AutoHotkey?

I am trying to add a delay between sent characters with something like this:

^`::SetKeyDelay,100 Send 67890

I think this code works:

^`::
SetKeyDelay, 100
Send 67890

The goal is to get that code into one line.

Upvotes: 2

Views: 9891

Answers (1)

John Dvorak
John Dvorak

Reputation: 27287

Autohotkey doesn't support multiple commands per line (semicolons denote line comments). The documentation itself states

Each script is a plain text file containing lines to be executed by the program (AutoHotkey.exe).

You could set the key delay globally (then each hotkey action is single-line):

SetKeyDelay, 100

;...

^`::Send 67890

Alternatively you could use a subroutine or a function:

type(speed, str){
  SetKeyDelay, %speed%
  Send, %str%
}

;...

^`::type(100, "67890")

It is also possible to use multiline hotkeys, but you need to delimit their end with return. This approach seems preferred by the documetation:

^`::
  SetKeyDelay, 100
  Send, 67890
return

Upvotes: 6

Related Questions