AutoIt Sleep Function

The sleep function can be used to pause the execution of scripts.

5321 views

Edited: 2017-12-19 17:54

The AutoIt Sleep function is used to pause scripts for a set amount of time. The sleep function accepts a value in milliseconds, the maximum value is 2147483647 (24 855.1348 days). If you want the script to pause longer then that, it may be better to repeatedly call sleep within a loop.

Sometimes you might run into systems with anti-automation measures that are intended to prevent scripts from using (or abusing) the system. Some of these can be avoided by using sleep in combination with random to make your script behave more human-like. Often, just using a sleep alone will be enough to avoid CAPTCHAs.

Reminder. 1000 milliseconds equals 1 second.

Sleep for 10 seconds, and continue running the script:

sleep(10000)

Using the sleep function

The below script will pause for 10 seconds, before clicking a given spot on the screen.

sleep(10000)
MouseClick("primary", 200, 150, 5)

To randomize the amount of sleep time we can use the Random function. The below Generates a number between 1000 and 5000, then pauses using the generated number.

sleep(random(1000, 5000, 1)) ; Generates a number between 1000 and 5000

Parameters

DelayAmount of time to pause in milliseconds.

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials