This article mainly introduces AutoIt's script syntax features, including variables, keywords, macros, setting options, detailed syntax details, can refer to its user manual, can also go to AutoIt Chinese Forum (www.autoit.net.cn) Exchange.
1. Variables
AutoIt variable naming rules: Letters, numbers, and underscores that begin with $ , such as $name, $Jone _wang, $Num 001, are legal.
Define variables that can be defined using global, dim, or local. For example: Dim $Name, Global $Name, Local $Name. The differences are as follows:
Global, declaring Globals
Local variables, such as function internal variables, are declared
Dim, if the variable name and global variable have the same name, the global variable is reused, otherwise it is just a local variable.
2. Common keywords
Include, containing a file into the script, usage: #include "[path \] filename";
Include-once, specifies that the current file can only be included once. If you do not use this keyword declaration, the compiler will error if a library file is referenced more than once. Usage: #include-once;
CS, Comment Line start, ce: Comment Line end, both with use, namely #cs ... #ce;
Comment A line of code separately, you can use the semicolon ";" Comments .
3. Macros
AutoIt provides a large number of macros, which greatly facilitates the writing of scripts. macros start with @ , such as @osversion returns the current operating system version, @ProgramFilesDir return to the Program Files folder path, @YEAR returns the current year (4 digits), and so on. For more macros, see AutoIt Help.
4. Setting options
AutoIt can use the OPT () function to implement various runtime settings, such as:
Opt ("Mousecoordmode", 1) sets the mouse function to use the absolute coordinate value of the screen;
Opt ("Mousecoordmode", 0) sets the mouse function to listen to relative coordinate values using the current activation window;
Opt ("Wintitlematchmode", 1) Sets the window function title to match when starting from scratch to match the title;
Opt ("Wintitlematchmode", 2) Sets the window function to match the caption according to the specified substring pattern.
For more configuration options, see Help for the OPT () function.
5. Built-in functions
AutoIt contains a large number of commonly used functions, mainly including: Operation window and control class, control mouse keyboard class, file Directory management class, String processing class, etc., basically can meet the overwhelming majority of needs. At the same time, the official package also has a large number of third-party library functions, the network is also a lot of people are constantly expanding library functions. If you can't find the special function function you need, we can also write our own function.
6. How to Write library functions
When we write a script for a complex application, there may be a number of functional segments that recur. To reduce the effort and complexity of scripting and maintenance scripts, we can encapsulate those scripts that contain the same logic into functions, organize them into different files by feature or type characteristics, and then include them in scripts that use these functions. How to write a function:
Embed the function code between Func and Endfunc.
Defines the function's parameters and their return values.
The function name must begin with a letter or underscore "_". Valid function names such as MyFunc, FUNC1, _MY_FUNC1, and so on.
Here is an example function that functions to return a value after a number of minutes.
; Head.au3func mydouble ($value) $value = $value * 2 Return $valueEndFunc
The AutoIt installation package comes with a number of very useful library functions, with a very detailed description of the use of each function in its help documentation. When you write a script, you can recall the view at any time by F1 key. When you use these library functions, you need to include the corresponding library files (such as # include <Array.au3>) in your script.
Syntax characteristics of AutoIt scripts