Tải bản đầy đủ (.docx) (1,051 trang)

Tự học AutoIT

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (4.56 MB, 1,051 trang )

v3.3.8.0
©1999-2011 Jonathan Bennett & AutoIt Team
AutoIt v3 Homepage
AutoIt Documentation
• Introduction
• License
• Installation Directory
• Frequently Asked Questions (FAQ)
• Credits
• History / ChangeLog
• History of AutoIt and Developers
Using AutoIt
• Running Scripts
• AutoIt on Windows Vista
• Command Line Parameters
• Script Editors
• Compiling Scripts
• AutoIt Window Info Tool (AU3Info)
• Window Titles and Text (Basic)
• Window Titles and Text (Advanced)
• Controls
• Unicode Support
• Intended Use
• Notes for AutoIt v2 Users
• Running under Windows 64-bit Edition
Tutorials
• My First Script (Hello World)
• Simple Notepad Automation
• WinZip Installation
• String Regular expression
Language Reference


• Datatypes
• Variables
• Macros
• Operators
• Conditional Statements
• Loop Statements
• Functions
• Comments
GUI Reference
• GUI Concepts
• GUI MessageLoop Mode
• GUI OnEvent Mode
Keyword Reference
• Keyword Reference
Macro Reference
• Macro Reference
Function Reference
• Function Reference
Appendix
• AutoIt3 limits/defaults
• ASCII Characters
• CLSIDs of Special Folders
• GUI Control Styles
• Splash Fonts
• @OSLang Values
• Send Key List
• Windows Message Codes




v3.3.8.0
©1999-2011 Jonathan Bennett & AutoIt Team
AutoIt v3 Homepage
Introduction
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 (e.g. VBScript and SendKeys). AutoIt is also
very small, self-contained and will run on all versions of Windows out-of-the-box with
no annoying "runtimes" required!
AutoIt was initially designed for PC "roll out" situations to reliably automate and
configure thousands of PCs. Over time it has become a powerful language that supports
complex expressions, user functions, loops and everything else that veteran scripters
would expect. Features:
• Easy to learn BASIC-like syntax
• Simulate keystrokes and mouse movements
• Manipulate windows and processes
• Interact with all standard windows controls
• Scripts can be compiled into standalone executables
• Create Graphical User Interfaces (GUIs)
• COM support
• Regular expressions
• Directly call external DLL and Windows API functions
• Scriptable RunAs functions
• Detailed helpfile and large community-based support forums
• Compatible with Windows 2000 / XP / 2003 / Vista / 2008 / 7
• Unicode and x64 support
• Digitally signed for peace of mind
• Works with Windows Vista's User Account Control (UAC)
AutoIt has been designed to be as small as possible and stand-alone with no external

.dll files or registry entries required making it safe to use on Servers. Scripts can be
compiled into stand-alone executables with Aut2Exe.
Also supplied is a combined COM and DLL version of AutoIt called AutoItX that allows
you to add the unique features of AutoIt to your own favourite scripting or
programming languages!
Best of all, AutoIt continues to be FREE - but if you want to support the time, money and
effort spent on the project and web hosting then you may donate at the AutoIt
homepage.

Features in Detail
Basic-like Syntax and Rich Function Set
AutoIt has a BASIC-like syntax which means that most people who have ever written a
script or used a high-level language should be able to pick it up easily.
Although it started life as a simple automation tool, AutoIt now has functions and
features that allow it to be used as a general purpose scripting language (with awesome
automation as well of course!). Language features include:
• The usual high-level elements for functions, loops and expression parsing
• A staggering amount of string handling functions and a Perl compatible regular
expression engine (using the PCRE library).
• COM support
• Call Win32 and third-party DLL APIs

Built-in Editor with Syntax Highlighting
AutoIt comes with a customised "lite" version of SciTE that makes editing scripts easy.
Users can also download a complete version of SciTE that includes additional tools to
make things even easier.

Standalone and Small
AutoIt is a very small and standalone application with no reliance on massive runtimes
like .NET or VB. All you need to run AutoIt scripts are the main AutoIt executable

(AutoIt3.exe) and the script. Scripts can also be encoded into standalone executables
with the built-in script compiler Aut2Exe.

International and 64-bit Support
AutoIt is fully Unicode aware and also includes x64 versions of all the main components!
How many other free scripting languages can you say that about?

Key and Mouse Simulation
Much time has been spent optimizing the keystroke and mouse simulation functions to
be as accurate as possible on all versions of Windows. All the mouse and keyboard
routines are highly configurable both in terms of simulation "speed" and functionality.

Window Management
You can expect to move, hide, show, resize, activate, close and pretty much do what you
want with windows. Windows can be referenced by title, text on the window, size,
position, class and even internal Win32 API handles.

Controls
Directly get information on and interact with edit boxes, check boxes, list boxes,
combos, buttons, status bars without the risk of keystrokes getting lost. Even work with
controls in windows that aren't active!

Graphical User Interfaces (GUIs)
AutoIt v3 will also allow you to create some complex GUIs - just like those below!



And much, much more




Software License
AutoIt
Author : Jonathan Bennett and the AutoIt Team
WWW : />Email : support at autoitscript dot com
________________________________________________________
END-USER LICENSE AGREEMENT FOR THIS SOFTWARE
This End-User License Agreement ("EULA") is a legal agreement between you (either an
individual or a single entity) and the mentioned author of this Software for the software
product identified above, which includes computer software and may include associated
media, printed materials, and "online" or electronic documentation ("SOFTWARE
PRODUCT"). By installing, copying, or otherwise using the SOFTWARE PRODUCT, you
agree to be bound by the terms of this EULA. If you do not agree to the terms of this
EULA, do not install or use the SOFTWARE PRODUCT.

SOFTWARE PRODUCT LICENSE
The SOFTWARE PRODUCT is protected by copyright laws and international copyright
treaties, as well as other intellectual property laws and treaties. The SOFTWARE
PRODUCT is licensed, not sold.
The definition of SOFTWARE PRODUCT does not includes any files generated by the
SOFTWARE PRODUCT, such as compiled script files in the form of standalone
executables.
1. GRANT OF LICENSE
This EULA grants you the following rights:
Installation and Use. You may install and use an unlimited number of copies of the
SOFTWARE PRODUCT.
Reproduction and Distribution. You may reproduce and distribute an unlimited number
of copies of the SOFTWARE PRODUCT either in whole or in part; each copy should
include all copyright and trademark notices, and shall be accompanied by a copy of this
EULA. Copies of the SOFTWARE PRODUCT may be distributed as a standalone product

or included with your own product.
Commercial Use. You may use the SOFTWARE PRODUCT for commercial purposes. You
may sell for profit and freely distribute scripts and/or compiled scripts that were created
with the SOFTWARE PRODUCT.
Reverse engineering. You may not reverse engineer or disassemble the SOFTWARE
PRODUCT or compiled scripts that were created with the SOFTWARE PRODUCT.
2. COPYRIGHT
All title and copyrights in and to the SOFTWARE PRODUCT (including but not limited to
any images, photographs, animations, video, audio, music, text, and "applets"
incorporated into the SOFTWARE PRODUCT), the accompanying printed materials, and
any copies of the SOFTWARE PRODUCT are owned by the Author of this Software. The
SOFTWARE PRODUCT is protected by copyright laws and international treaty provisions.
Therefore, you must treat the SOFTWARE PRODUCT like any other copyrighted material.

MISCELLANEOUS
If you acquired this product in the United Kingdom, this EULA is governed by the laws of
the United Kingdom. If this product was acquired outside the United Kingdom, then
local law may apply.
Should you have any questions concerning this EULA, or if you desire to contact the
author of this Software for any reason, please contact him/her at the email address
mentioned at the top of this EULA.

LIMITED WARRANTY
1. NO WARRANTIES
The Author of this Software expressly disclaims any warranty for the SOFTWARE
PRODUCT. The SOFTWARE PRODUCT and any related documentation is provided "as is"
without warranty of any kind, either express or implied, including, without limitation, the
implied warranties or merchantability, fitness for a particular purpose, or non-
infringement. The entire risk arising out of use or performance of the SOFTWARE
PRODUCT remains with you.

2. NO LIABILITY FOR DAMAGES
In no event shall the author of this Software be liable for any damages whatsoever
(including, without limitation, damages for loss of business profits, business interruption,
loss of business information, or any other pecuniary loss) arising out of the use of or
inability to use this product, even if the Author of this Software has been advised of the
possibility of such damages. Because some states/jurisdictions do not allow the
exclusion or limitation of liability for consequential or incidental damages, the above
limitation may not apply to you.

[END OF LICENSE]

Install Directory Structure
The AutoIt installer creates a directory structure (usually located in \Program
Files\AutoIt3) summarized in the following table. The installer also creates Start Menu
shortcuts, but no other files are added or modified.
Files and Directories Description
(Top-level files)
AutoIt3.exe
The AutoIt main program and only file required to run
scripts!
AutoIt3_x64.exe The x64 version of AutoIt (if installed).
AU3Info.exe The AutoIt Window Info Tool.
AU3Info_x64.exe The x64 version of Au3Info (if installed).
AU3Check.exe The AutoIt syntax checker.
AutoIt.chm This help file which use AutoIt3.chm and UDFs3.chm
Uninstall.exe The AutoIt uninstaller.
AutoIt v3 Website.url A shortcut to />Aut2Exe
Icons\ Contains icons used for the .au3 filetype icon in Explorer.
Aut2Exe.exe The script compiler.
Aut2Exe_x64.exe The x64 version of Aut2Exe (if installed).

AutoItSC.bin Executable stub for compiled scripts.

AutoItSC_x64.bi
n
x64 executable stub for compiled scripts.
UPX.exe The UPX compressor (shinks the size of exe files).
Examples
COM\ Contains examples of COMs written in AutoIt.
GUI\ Contains examples of GUIs written in AutoIt.
Helpfile\ Contains scripts used in many of the help file examples.
Extras
Au3Record\
Contains Au3Record.exe to capture user interaction to be
converted as a script.
AutoUpdateIt\
Contains a script for easily retrieving the latest version of
AutoIt3.
Editors\
Contains syntax coloring definitions for some popular text
editors.
SQLite\ Contains SQLite command line executable and an help file.
Icons
Contains icons used for the .au3 filetype icon in Explorer.
Include
Contains standard include files (pre-written user functions). See the Library
Functions)
AutoItX
Contains a DLL version of AutoIt v3 that provides a subset of the features of
AutoIt via an ActiveX/COM and DLL interface.
SciTE

Contains a light version of SciTE which allows syntax coloring.
It should be repeated that to run AutoIt scripts, the only required file is AutoIt3.exe. If
you compile a script into an executable then a user does not require AutoIt to be
installed to run that compiled executable.

Registry Keys
The AutoIt installer creates registry keys under HKEY_LOCAL_MACHINE\Software\AutoIt
v3 and HKEY_CURRENT_USER\Software\AutoIt v3. The keys are NOT used/created when
AutoIt utilities are run on machines that lack a full AutoIt installation AutoIt is "clean"
to run on servers, etc.

The table below shows the default (or typical) registry keys. The keys in italic are not
created by the installer itself but by the first execution of the corresponding utility:
HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\
AutoIt
(Default) REG_SZ (value not set)
InstallDir REG_SZ C:\Program Files\AutoIt3
Version REG_SZ Version Number
HKEY_CURRENT_USER\Software\AutoIt v3\
Aut2Exe
(Default) REG_SZ (value not set)
AllowDecompile* REG_DWORD 0x1
LastCompression REG_DWORD 0x2
LastExeDir REG_SZ My Documents
LastIcon REG_SZ
LastIconDir REG_SZ
C:\Program
Files\AutoIt3\Aut2Exe\Icons
LastScriptDir REG_SZ My Documents
AutoUpdateIt

(Default) REG_SZ (value not set)
DoneOption REG_SZ Notify
DownloadDir REG_SZ C:\Downloads\ForExample\
AU3Info
Default REG_SZ (value not set)
AlwaysOnTop REG_DWORD 0x1
ColorMode REG_DWORD 0x1
CoordMode REG_DWORD 0x1
HighlightColor REG_DWORD 0x0
HighlightControls REG_DWORD 0x1
Magnify REG_DWORD 0x0
WinH REG_DWORD 0x01c2
WinW REG_DWORD 0x012c
WinX REG_DWORD 0x0064
WinY REG_DWORD 0x0064
* - AllowDecompile will only work with AutoIt V3.2.5.1 or earlier.



Frequently Asked Questions (FAQ)
This section gives some of the more frequently asked questions from the forum. If you
can't find the answer you seek here then the forum should be your first port of call.
Questions
1. Why doesn't my old AutoIt v2.64 script run in v3?
2. Isn't v3 much more difficult than previous versions?
3. How can I convert my v2.64 scripts to v3?
4. Where is the "goto" command?
5. How can I run a DOS program from within AutoIt?
6. Why can I only use Run() to execute .exe and .com files? What about .msi / .txt and
others?

7. Why do I get errors when I try and use double quotes (") ?
8. What do the window "title" and "text" parameters mean?
9. Why can't I print a variable using "My var is $variable"?
10. When I use Send() to send a variable odd things happen?
11. What is the difference between the return value and @error?
12. How can I exit my script with a hot-key?
13. How can I use a custom icon when compiling my scripts?
14. How can I make sure only one copy of my script is run?
15. What are the current technical limits of AutoIt v3?
16. I get a missing picture symbol in the Help file under the Examples.


1. Why doesn't my old AutoIt v2.64 script run in v3?
v3 has a different language structure to v2.64.
Previous versions of AutoIt were fine for what they were designed for - writing simple
scripts to help with software installations. Over time people began using it for general
and complicated scripting tasks. The old syntax and structure made this possible but
very very difficult and cumbersome. The decision was made to make AutoIt more
suitable for general automation tasks and to achieve that a more standard and basic-like
language was made. This also means that if you already know a scripting language you
will pick AutoIt v3 up easily.

Back To Top
2. Isn't v3 much more difficult than previous versions?
No. In fact in many instances it's much easier than previous versions as you don't have
to try and force the language to do something it was never designed to do. It also uses
a familiar BASIC-like language, and BASIC is known for being well basic :)

The vast majority of old AutoIt scripts were focused around software installation and
clicking "Next" a lot in dialog boxes. Most of these scripts can be converted to v3

simply by adding a couple of brackets here and there. Here is an example of such a
script in v2 and v3 (simulating a software installation with a few dialogs that have a Next
button and a Finish button)

; v2.64 Script
WinWaitActive, Welcome, Welcome to the XSoft installation
Send, !n
WinWaitActive, Choose Destination, Please choose the
Send, !n
WinWaitActive, Ready to install, Click Next to install
Send, !n
WinWaitActive, Installation Complete, Click Finish to exit
Send, !f
WinWaitClose, Installation Complete
; v3 Script
WinWaitActive("Welcome", "Welcome to the XSoft installation")
Send("!n")
WinWaitActive("Choose Destination", "Please choose the")
Send("!n")
WinWaitActive("Ready to install", "Click Next to install")
Send("!n")
WinWaitActive("Installation Complete", "Click Finish to exit")
Send("!f")
WinWaitClose("Installation Complete")

Now, that wasn't so bad! :) As all "strings" are enclosed in quotes you no longer have to
wrestle with problems caused by leading and trailing spaces in text. There is also
fantastic support for many text editors so that when you are writing v3 scripts you can
have syntax highlighting which makes everything much easier.


Back To Top
3. How can I convert my v2.64 scripts to v3?
The first thing you should ask yourself is "Do I need to convert my script?". v2.64 will
continue to be downloadable and supported so don't update all your scripts just for the
sake of it - well not unless you want to :)

There is a section in the Help file that shows how the commands in v2 and v3 are related
- click here to see the page.

One of the AutoIt v3 authors has written a utility to automatically convert v2 scripts to
v3. Conversion is pretty good unless your code is a rats-nest of gotos :) You can find
the converter in the "Extras" directory (Start \ AutoIt v3 \ Extras - or look in the directory
that you installed AutoIt v3).

Back To Top
4. Where is the "goto" command?
Gone. It's evil. No, you can't ask why - it just is. It's like that lump of rock they find in
the microwave at the end of the film Time Bandits :)

AutoIt v3 features most of the common "loops" in use today and with these Goto is no
longer required. Look up While, Do, For, ExitLoop, ContinueLoop and Functions for the
modern way of doing things :) And while you are looking at help file sections check out
these on loops, conditional statements and functions. I promise you, once you have got
the hang of such things you will be able to script in virtually any other language within a
couple of minutes.

Just to get you started, the most basic use of Goto in version 2.64 was an infinite loop
like:
:mylabel
do something

and something else
goto, mylabel
A simple v3 version of that is a While loop that is always "true".
While 1 = 1
do something
do something else
Wend

Back To Top
5. How can I run a DOS program from within AutoIt?
If you wanted to run something like a DOS "Dir" command then you must run it though
the command interpreter (command.com or cmd.exe depending on your OS). The
@Comspec macro contains the correct location of this file. You should use the
RunWait() function as it waits for the DOS program to finish before continuing with the
next line of the script. Here is an example of running the DOS Dir command on the C:
drive: (effectively running the command command.com /c Dir C:\ )
RunWait(@COMSPEC & " /c Dir C:\")

Back To Top
6. Why can I only use Run() to execute .exe files? What
about .msi / .txt and others?
Only a few file extensions are usually "runable" - these are .exe, .bat, .com, .pif. Other
file types like .txt and .msi are actually executed with another program. When you
double click on a "myfile.msi" file what actually happens in the background is that
"msiexec.exe myfile.msi" is executed. So to run a .msi file from AutoIt you would do:
RunWait("msiexec myfile.msi")

Or, run the command "start" which will automatically work out how to execute the file
for you:
RunWait(@COMSPEC & " /c Start myfile.msi")


Or, use the ShellExecuteWait function which will automatically work out how to execute
the file for you:
ShellExecuteWait("myfile.msi")

Back To Top
7. Why do I get errors when I try and use double
quotes (") ?
If you want to use double-quotes inside a string then you must "double them up". So
for every one quote you want you should use two. For example if you wanted to set a
variable to the string: A word in "this" sentence has quotes around it! You would do:
$var = "A word in ""this"" sentence has quotes around it!"
or use single quotes instead:
$var = 'A word in "this" sentence has quotes around it!'

Back To Top
8. What do the window "title" and "text" parameters
mean?
There is a detailed description here.

Back To Top
9. Why can't I print a variable using "My var is
$variable"?
If you have a variable called $msg and you want to print in inside a MsgBox then this
will NOT work:
MsgBox(0, "Example", "My variable is $msg")
It will actually print My variable is $msg . What you need to do is tell AutoIt to join the
string and the variable together using the & operator:
MsgBox(0, "Example", "My variable is " & $msg)


Advanced: If you have many variables to add into a string then you may find the
StringFormat() function useful. For example, if I wanted to insert $var1 to $var5 into a
string then it may be easier to do:
$msg = StringFormat("Var1 is %s, Var2 is %s, Var3 is %s, Var4 is %s, Var5 is %s",
$var1, $var2, $var3, $var4, $var5)
MsgBox(0, "Example", $msg)

Back To Top
10. When I use Send() to send a variable odd things
happen?
If you are sending the contents of a variable then be mindful that if it contains special
send characters like ! ^ + {SPACE} then these will be translated into special keystrokes -
rarely what is wanted. To overcome this use the RAW mode of Send() that does not
translate special keys:
Send($myvar, 1)

Back To Top
11. What is the difference between the return value
and @error?
Generally a return value is used to indicate the success of a function. But, if a function is
already returning something ( like WinGetText() ) then we need to have a way of
working out if the function was successful, so we set @error instead.

Back To Top
12. How can I exit my script with a hot-key?
Ah, an easy one. If you want to make your script exit when you press a certain key
combination then use the HotKeySet() function to make a user function run when the
desired key is pressed. This user function should just contain the Exit keyword.
Here some code that will cause the script to exit when CTRL+ALT+x is pressed:
HotKeySet("^!x", "MyExit")



; Rest of Script


Func MyExit()
Exit
EndFunc

Back To Top
13. How can I use a custom icon when compiling my
scripts?
You need to run the full compiler program (rather than just right-clicking a script and
selecting compile). This page describes the compiler in detail.

Back To Top
14. How can I make sure only one copy of my script is
run?
Use the _Singleton() function. See the User Defined Functions documentation for more
information on _Singleton() and how to use it.
Back To Top
15. What are the current technical limits of AutoIt v3?
Here are details of the current technical limits of AutoIt. Please note that some of the
limits are theoretical and you may run into performance or memory related problems
before you reach the actual limit.

Maximum length of a single script line: 4,095
Maximum string length: 2,147,483,647 characters
Number range (floating point): 1.7E–308 to 1.7E+308 with 15-digit precision
Number range (integers): 64-bit signed integer

Hexadecimal numbers: 32-bit signed integer (0x80000000 to 0x7FFFFFFF)
Arrays: A maximum of 64 dimensions and/or a total of 16 million elements
Maximum depth of recursive function calls: 5100 levels
Maximum number of variables in use at one time: No limit
Maximum number of user defined functions: No limit
Maximum number of GUI windows: No limit
Maximum number of GUI controls: 65532

Back To Top
16. I get a missing picture symbol in the Help file
under the Examples.
This should be the Open button that enable you to open the Examples in the Help file.
This issue is that the hhctrl.ocx isn't properly registered or corrupted.
Try registering it by doing "regsvr32 hhctrl.ocx" from the command prompt or check if
the file is still valid.

Back To Top






































Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×