Learning to Script with Autoit V3 Document Last Updated 17 February 2010 Autoit Version 3.3.0.0
Total Page:16
File Type:pdf, Size:1020Kb
Learning to Script with AutoIt V3 Document last updated 17 February 2010 AutoIt Version 3.3.0.0 Original Document: Alex Peters (LxP) http://yallara.cs.rmit.edu.au/~apeters/ Updated By: Brett Francis (BrettF) http://signa5.com This document is for you if you are interested in learning to script with AutoIt. Where possible, I will try to assume that you have no prior coding experience and I aim to teach you some good general coding habits, which will be beneficial should you decide to move on to other languages. Table of Contents Acknowledgements ................................................................................................................................. 6 Introduction ............................................................................................................................................ 7 What Is AutoIt? ................................................................................................................................... 7 Features of AutoIt ............................................................................................................................... 7 A little about this tutorial .................................................................................................................... 7 1 Starting Off ........................................................................................................................................... 8 1.1 Download and Install AutoIt V3 .................................................................................................... 8 1.2 Install SciTE4AutoIt3 ..................................................................................................................... 8 1.3 Know how to access the help file .................................................................................................. 9 1.4 Know what you want to achieve ................................................................................................... 9 1.5 What is contained in this tutorial? ................................................................................................ 9 2 Your First Steps .................................................................................................................................. 10 2.1 Creating and Organizing Script Files ........................................................................................... 10 2.2.1 Organization of Scripts ......................................................................................................... 10 2.1.2 Creating a Script from Explorer ............................................................................................ 10 2.1.3 Creating a Script from SciTE ................................................................................................. 11 2.2 Hello World Example .................................................................................................................. 11 2.2. 1 The Steps ............................................................................................................................. 11 2.2.2 Explanation .......................................................................................................................... 11 2.2.3 Extended Work .................................................................................................................... 12 2.2.4 The Code .............................................................................................................................. 13 2.3 Simple Notepad Automation ...................................................................................................... 13 2.4. 1 The Steps ............................................................................................................................. 13 2.3.2 Explanation .......................................................................................................................... 15 2.3.3 Extended Work .................................................................................................................... 15 2.3.4 The Code .............................................................................................................................. 15 2.5 Exercies ....................................................................................................................................... 17 3 Programming—it’s all about values ................................................................................................... 18 3.1 How values are used ................................................................................................................... 18 3.2 Different types of values ............................................................................................................. 19 3.3 Values in Depth ........................................................................................................................... 19 3.3.1 Numeric Values .................................................................................................................... 19 3.3.2 Strings .................................................................................................................................. 19 LEARNING TO SCRIPT WITH AUTOIT V3 Page 2 3.3.3 Booleans ............................................................................................................................... 20 3.4 Exercises ...................................................................................................................................... 21 4 Arrays of Variables ............................................................................................................................. 22 4.1 Declaring and naming variables .................................................................................................. 22 4.2 The Naming Convention ............................................................................................................. 23 4.3 Assigning variable values ............................................................................................................ 23 4.4 Accessing variable values ............................................................................................................ 23 4.5 Constants .................................................................................................................................... 24 4.6 Macros ........................................................................................................................................ 24 4.7 Arrays .......................................................................................................................................... 26 4.8 Exercises ...................................................................................................................................... 27 5 Functions ............................................................................................................................................ 28 5.1 Example function calls ................................................................................................................ 29 5.1.1 Run() and RunWait() ............................................................................................................ 29 5.1.2 WinWait() ............................................................................................................................. 29 5.1.3 Send() ................................................................................................................................... 30 5.2 Exercises .................................................................................................................................. 31 6 Operators ........................................................................................................................................... 32 6.1 True or False? .............................................................................................................................. 34 True ............................................................................................................................................... 34 False .............................................................................................................................................. 34 6.2 Exercises ...................................................................................................................................... 35 7 Branching ........................................................................................................................................... 36 7.1 Conditional Functions ................................................................................................................. 36 7.1.1 If…Then…Else ....................................................................................................................... 36 7.1.2 Select Case ........................................................................................................................... 36 7.1.3 Switch Case .......................................................................................................................... 36 7.1.4 ContinueCase ....................................................................................................................... 37 7.2 Exercises ...................................................................................................................................... 38 8 Loops