What is AutoIT ? AutoIT Options and Functions

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting

  • It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages
  • Features Include:
  • Manipulate windows and processes
  • Interact with all standard windows controls
  • Scripts can be compiled into standalone executables
  • Create Graphical User Interfaces (GUIs)
  • Supports Regular expressions

 


AutoIT Options

# Tags

Specifies certain keywords with predefined functions

#comments-start Specify that an entire section of script should be commented out.
#include-once Specifies that the current file may only be included once.
#include Includes a file in the current script.
#NoAutoIt3Execute Specifies that the current compiled script cannot run with /AutoIt3ExecuteLine or /AutoIt3ExecuteScript switch.
#NoTrayIcon Indicates that the AutoIt tray icon will not be shown when the script starts.
#OnAutoItStartRegister Registers a function to be called when AutoIt starts.
#RequireAdmin Specifies that the current script requires full administrator rights to run.

 


@ Tags

Predefined Macros that can be used with AutoIT.

@ScriptName Filename of the running script.
@ScriptDir Directory containing the running script.  (Result does not contain a trailing backslash)
@ScriptFullPath Equivalent to @ScriptDir & “\” & @ScriptName
@SW_MAXIMIZE Maximizes the specified window.
@SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.
@DesktopDir path to current user’s  Desktop
@MyDocumentsDir path to My Documents target

 


Math functions

Some of the predefined keyword functions for math calculations.

Exp Calculates e to the power of a number.
Floor Returns a number rounded down to the closest integer.
Log Calculates the natural logarithm of a number.
Mod Performs the modulus operation.
Random Generates a pseudo-random float-type number.
Round Returns a number rounded to a specified number of decimal places.
Sin Calculates the sine of a number.
Sqrt Calculates the square-root of a number.

 


SEND

SEND simulates keystrokes to the current window.

Send Command (if zero flag) Resulting Keypress
{!} !
! ALT
^ SHIFT
# WINDOWS
+ CTRL
{SPACE} SPACE
{ENTER} ENTER key on the main keyboard
{ALT} ALT

 


Includes Files

These contain prewritten functions for AutoIt and should be used with “#Include”.

Array.au3 Functions that assist with array management
Date.au3 Functions that assist with dates and times
File.au3 Functions that assist with files and directories
GuiCombo.au3 Functions that assist with ComboBox
GUIConstants.au3 Includes all GUI related constants
IE.au3 Internet Explorer Automation UDF Library for Auto-It3
Inet.au3 Functions that assist with the Internet

 


SLEEP

  • This Function is used to delay script execution.
  • “Sleep ( delay )”.
delay Amount of time to pause (in milliseconds).

 


_SINGLETON

  • Used to enforce a design paradigm where only one instance of the script may be running.
  • “_Singleton($sOccurenceName [, $iFlag = 0])”.
$sOccurenceName String to identify the occurrence of the script. This string may not contain the \ character unless you are placing the object in a namespace (See Remarks).
$iFlag [optional] Behavior options.
0 – Exit the script with the exit code -1 if another instance already exists.
1 – Return from the function without exiting the script.
2 – Allow the object to be accessed by anybody in the system. This is useful if specifying a “Global\” object in a multi-user environment.

 


Windows Functions

Using Clipboard

When using them you need to add a #include <Clipboard.au3>.

_ClipBoard_Open Opens the clipboard and prevents other applications from modifying the clipboard
_ClipBoard_RegisterFormat Registers a new clipboard format
_ClipBoard_SetData Places data on the clipboard in a specified clipboard format
_ClipBoard_GetData Retrieves data from the clipboard in a specified format
_ClipBoard_GetDataEx Retrieves data from the clipboard in a specified format
_ClipBoard_GetFormatName Retrieves the name of the specified registered format

 


Macro References

@CPUArch Returns “X86” when the CPU is a 32-bit CPU and “X64” when the CPU is 64-bit.
@OSArch Returns one of the following: “X86”, “IA64”, “X64” – this is the architecture type of the currently running operating system.
@OSLang Returns code denoting OS Language.  See Appendix for possible values.
@OSVersion Returns one of the following: “WIN_2008R2”, “WIN_7”, “WIN_2008”, “WIN_VISTA”, “WIN_2003”, “WIN_XP”, “WIN_XPe”, “WIN_2000”.
@OSBuild Returns the OS build number.  For example, Windows 2003 Server returns 3790
@OSServicePack Service pack info in the form of “Service Pack 3” or, for Windows 95, it may return “B”

 


Mouse Management

MouseClick Perform a mouse click operation.
MouseClickDrag Perform a mouse click and drag operation.
MouseDown Perform a mouse down event at the current mouse position.
MouseGetCursor Returns the cursor ID Number for the current Mouse Cursor.
MouseGetPos Retrieves the current position of the mouse cursor.
MouseMove Moves the mouse pointer.
MouseUp Perform a mouse up event at the current mouse position.

 


File Management

FileGetPos Retrieves the current file position.
FileGetShortcut Retrieves details about a shortcut.
FileGetShortName Returns the 8.3 short path+name of the path+name passed.
ConsoleRead Read from the STDIN stream of the AutoIt script process.
ConsoleWrite Writes data to the STDOUT stream. Some text editors can read this stream as can other programs which may be expecting data on this stream.
DirMove Moves a directory and all sub-directories and files.
DirRemove Deletes a directory/folder.
DriveGetDrive Returns an array containing the enumerated drives.

 


Windows based Functions

WinActivate Activates (gives focus to) a window.
WinActive Checks to see if a specified window exists and is currently active.
WinClose Closes a window.
WinExists Checks to see if a specified window exists.
WinGetProcess Retrieves the Process ID (PID) associated with a window.
WinGetState Retrieves the state of a given window.
WinGetText Retrieves the text from a window.
WinGetTitle Retrieves the full title from a window.

 


Process Management

ProcessClose Terminates a named process.
ProcessExists Checks to see if a specified process exists.
ProcessGetStats Returns an array about Memory or IO infos of a running process.
ProcessSetPriority Changes the priority of a process
ProcessList Returns an array listing the currently running processes (names and PIDs).
ProcessWait Pauses script execution until a given process exists.
ProcessWaitClose Pauses script execution until a given process does not exist.
Run Runs an external program.

 


Date Functions

_NowDate Returns the current Date in the Pc’s format.
_NowTime Returns the current Time in the requested format.
_SetDate Sets the current date of the system
_SetTime Sets the current time of the system
_DateIsValid Checks the given date to determine if it is a valid date.
_DateTimeFormat Returns the date in the PC’s regional settings format.
_DateTimeSplit Split a string containing Date and Time into two separate Arrays.

 


Ping

  • Pings a host and returns the roundtrip-time.
  • “Ping ( “address/hostname” [, timeout] )”.
address/hostname Can be i.e. “www.autoitscript.com” or “87.106.244.38”.
timeout [optional] Is the time to wait for an answer in milliseconds (default is 4000).

 


Constructs in AutoIt

If…Then

  • Conditionally run a single statement
  • “If <expression> Then statement”
expression If the expression is true, the statement is executed.

 

If…ElseIf…Else…EndIf

  • If <expression> Then
    statements

    [ElseIf expression-n Then
    [elseif statements … ]]

    [Else
    [else statements]

    EndIf
expression If the expression is true, the first statement block is executed. If not, the first true ElseIf block is executed. Otherwise, the “Else” block is executed.

 

For…In…Next

Syntax :
For <$Variable> In <expression>
statements

Next
 

Variable A variable to which an element is being assigned
expression Must be an expression resulting in an Object, or an Array with at least one element

 

Do…Until

Syntax :
Do
statements

Until <expression>

expression The statements in between Do and Until are executed until the expression is true.

 


Bitwise Functions

BitAND

  • Performs a bitwise AND operation
  • “BitAND ( value1, value2 [, value n] )”
value1 The first number.
value2 The second number.
value n [optional] The nth number – up to 255 values can be specified.

 

BitNOT

  • Performs a bitwise NOT operation.
  • “BitNOT ( value )”
value The number to operate on.

 

BitOR

  • Performs a bitwise OR operation.
  • “BitOR ( value1, value2 [, value n] )”
value1 The first number.
value2 The second number.
value n [optional] The nth number – up to 255 values can be specified.

 

BitXOR

  • Performs a bitwise exclusive OR (XOR) operation.
  • “BitXOR ( value1, value2 [, value n] )”

 

value1 The first number.
Value2 The second number.
value n [optional] The nth number – up to 255 values can be specified.