SetKeyDelay

Sets the delay that will occur after each keystroke sent by Send and ControlSend.

SetKeyDelay [, Delay, PressDuration]

 

Parameters

Delay Time in milliseconds, which can be an expression. Use -1 for no delay at all and 0 for the smallest possible delay. Leave this parameter blank to retain the current Delay.
PressDuration

Certain games and other specialized applications may require a delay inside each keystroke; that is, after the press of the key but before its release.

Use -1 for no delay at all (default) and 0 for the smallest possible delay. Omit this parameter to leave the current PressDuration unchanged.

Note: PressDuration also produces a delay after any change to the modifier key state (CTRL, ALT, SHIFT, and WIN) needed to support the keys being sent.

This parameter can be an expression.

 

Remarks

A short delay (sleep) is automatically and invisibly done after every keystroke sent by Send or ControlSend. This is done to improve the reliability of scripts because a window sometimes can't keep up with a rapid flood of keystrokes.

Due to the granularity of the OS's time-keeping system, delays might be rounded up to the nearest multiple of 10. For example, a delay between 1 and 10 (inclusive) is equivalent to 10 on Windows XP (and probably NT & 2k).

A delay of 0 internally executes a Sleep(0), which yields the remainder of the script's timeslice to any other process that may need it. If there is none, Sleep(0) will not sleep at all. By contrast, a delay of -1 will never sleep. For better reliability, 0 is recommended as an alternative to -1.

When the delay is set to -1, a script's process-priority becomes an important factor in how fast it can send keystrokes. To raise a script's priority, use Process, Priority,, High. Although this typically causes keystrokes to be sent faster than the active window can process them, the system automatically buffers them. Buffered keystrokes continue to arrive in the target window after the Send command completes (even if the window is no longer active). This is usually harmless because any subsequent keystrokes sent to the same window get queued up behind the ones already in the buffer.

If unset, the default delay is 10 (20 for .aut scripts). The default PressDuration is -1.

The built-in variable A_KeyDelay contains the current setting of Delay. There is no built-in variable for PressDuration.

Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts off fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).

 

Related

Send, ControlSend, SetMouseDelay, SetControlDelay, SetWinDelay, SetBatchLines, MouseClick

 

Example

SetKeyDelay, 0