One of the newest features of AutoIT is its ability to create graphical user interfaces.
This feature adds an extraordinary amount of possibilities to the already useful
AutoIT language. Some of the most common uses of a GUI are installation menus,
input forms, and progress bars.
I am beginning this section with an example so you can see the layout of GUI creation
and get familiar with the functions used to create GUIs. Example 1 displays a two button
GUI with instructions and an image. It can be modified and used for anything
you can use a two-button chooser for: an installer for two different programs, a
chooser for two different types of users, etc. You can easily increase the size of the
GUI and create more buttons.
AutoIT Script X
AutoIT Scripts, Tips and Tutorials
Saturday, June 15, 2013
Example: Graphical User Interface - AI Smart Homes
; Includes the GuiConstants (required for GUI function usage)
#include <GuiConstants.au3>
; Hides tray icon
#NoTrayIcon
; Change to OnEvent mode
Opt('GUIOnEventMode', 1)
; GUI Creation
GuiCreate("Ai Smart Homes - Saint Louis, Missouri", 400, 300)
GuiSetIcon("icon.ico")
; Runs the GUIExit() function if the GUI is closed
GUISetOnEvent($GUI_EVENT_CLOSE, 'GUIExit')
; Logo / Pic
GuiCtrlCreatePic("logo.jpg",120,5,156,160)
; Instructions
GUICtrlCreateLabel("Please Choose an Option Below:", 50, 180, 300, 15, $SS_CENTER)
GUICtrlSetColor(−1,0xFF0000) ; Makes instructions Red
; Button1
GUICtrlCreateButton("Visit Our Website", 100, 210, 200, 30)
GUICtrlSetOnEvent(−1, 'website') ; Runs website() when pressed
; Button2
GUICtrlCreateButton("Send an Email", 100, 250, 200, 30)
GUICtrlSetOnEvent(−1, 'email') ; Runs email() when pressed
Func website()
; Hides the GUI while the function is running
GUISetState(@SW_HIDE)
Run("C:\Program Files\Internet Explorer\iexplore.exe www.aismarthomes.com")
Exit
EndFunc
Func email()
; Hides the GUI while the function is running
GUISetState(@SW_HIDE)
Run("mailto:contact@aismarthomes.com")
Exit
EndFunc
; Shows the GUI after the function completes
GUISetState(@SW_SHOW)
; Idles the script in an infinite loop - this MUST be included when using
OnEvent mode
While 1
Sleep(500)
WEnd
; This function makes the script exit when the GUI is closed
Func GUIExit()
Exit
EndFunc
#include <GuiConstants.au3>
; Hides tray icon
#NoTrayIcon
; Change to OnEvent mode
Opt('GUIOnEventMode', 1)
; GUI Creation
GuiCreate("Ai Smart Homes - Saint Louis, Missouri", 400, 300)
GuiSetIcon("icon.ico")
; Runs the GUIExit() function if the GUI is closed
GUISetOnEvent($GUI_EVENT_CLOSE, 'GUIExit')
; Logo / Pic
GuiCtrlCreatePic("logo.jpg",120,5,156,160)
; Instructions
GUICtrlCreateLabel("Please Choose an Option Below:", 50, 180, 300, 15, $SS_CENTER)
GUICtrlSetColor(−1,0xFF0000) ; Makes instructions Red
; Button1
GUICtrlCreateButton("Visit Our Website", 100, 210, 200, 30)
GUICtrlSetOnEvent(−1, 'website') ; Runs website() when pressed
; Button2
GUICtrlCreateButton("Send an Email", 100, 250, 200, 30)
GUICtrlSetOnEvent(−1, 'email') ; Runs email() when pressed
Func website()
; Hides the GUI while the function is running
GUISetState(@SW_HIDE)
Run("C:\Program Files\Internet Explorer\iexplore.exe www.aismarthomes.com")
Exit
EndFunc
Func email()
; Hides the GUI while the function is running
GUISetState(@SW_HIDE)
Run("mailto:contact@aismarthomes.com")
Exit
EndFunc
; Shows the GUI after the function completes
GUISetState(@SW_SHOW)
; Idles the script in an infinite loop - this MUST be included when using
OnEvent mode
While 1
Sleep(500)
WEnd
; This function makes the script exit when the GUI is closed
Func GUIExit()
Exit
EndFunc
FileInstall - Including Files in AutoIt Scripts
The FileInstall() function allows the inclusion of any file—such as an executable
or image file—in the compiled script executable. This is similar to #include, but
it dramatically increases the size of your compiled executable in most cases. This
is the syntax of the FileInstall() function:
FileInstall("sourcefile","destination" [,flag])
The flags for FileInstall() are optional. A flag of 0 tells the function not to overwrite
existing files. Use a flag of 1 if you would like to overwrite any existing files
the script may encounter. The source file cannot be a variable; it must be a string,
and it cannot contain wildcards.
Example 1 is an installation you can perform with the FileInstall() function that
extracts all installation files to the temp directory. When compiled, the entire installation
is a single executable.
Example 1. Using the FileInstall() Function
#NoTrayIcon
Opt("MustDeclareVars", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\Setup.exe", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\setup.ico", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\setup.ini", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\program.dll", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\readme.txt", 1)
Run(@TempDir & "\Setup.exe")
WinWait("Installation Wizard", "Welcome to the")
If Not WinActive("Installation Wizard", "Welcome to the") Then _
WinActivate("Installation Wizard", "Welcome to the")
WinWaitActive("Installation Wizard", "Welcome to the")
ControlClick("Installation Wizard", "", "Next")
WinWait("Installation Wizard", "Installation Complete")
If Not WinActive("Installation Wizard", "Installation Complete") Then _
WinActivate("Installation Wizard", "Installation Complete")
WinWaitActive("Installation Wizard", "Installation Complete")
ControlClick("Installation Wizard", "", "Finish")
In this example, FileInstall() copies five files to the temp directory, then the Run
() command runs Setup.exe. The program then waits for the installation wizard to
appear using WinWait() and makes it active using WinActivate() before clicking
Next with ControlClick() and then Finish with ControlClick() to complete the
installation.
or image file—in the compiled script executable. This is similar to #include, but
it dramatically increases the size of your compiled executable in most cases. This
is the syntax of the FileInstall() function:
FileInstall("sourcefile","destination" [,flag])
The flags for FileInstall() are optional. A flag of 0 tells the function not to overwrite
existing files. Use a flag of 1 if you would like to overwrite any existing files
the script may encounter. The source file cannot be a variable; it must be a string,
and it cannot contain wildcards.
Example 1 is an installation you can perform with the FileInstall() function that
extracts all installation files to the temp directory. When compiled, the entire installation
is a single executable.
Example 1. Using the FileInstall() Function
#NoTrayIcon
Opt("MustDeclareVars", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\Setup.exe", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\setup.ico", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\setup.ini", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\program.dll", 1)
FileInstall("C:\Documents and Settings\Administrator\Desktop\Program\" & _
"Setup.exe", @TempDir & "\readme.txt", 1)
Run(@TempDir & "\Setup.exe")
WinWait("Installation Wizard", "Welcome to the")
If Not WinActive("Installation Wizard", "Welcome to the") Then _
WinActivate("Installation Wizard", "Welcome to the")
WinWaitActive("Installation Wizard", "Welcome to the")
ControlClick("Installation Wizard", "", "Next")
WinWait("Installation Wizard", "Installation Complete")
If Not WinActive("Installation Wizard", "Installation Complete") Then _
WinActivate("Installation Wizard", "Installation Complete")
WinWaitActive("Installation Wizard", "Installation Complete")
ControlClick("Installation Wizard", "", "Finish")
In this example, FileInstall() copies five files to the temp directory, then the Run
() command runs Setup.exe. The program then waits for the installation wizard to
appear using WinWait() and makes it active using WinActivate() before clicking
Next with ControlClick() and then Finish with ControlClick() to complete the
installation.
Monday, April 4, 2011
Finding the Correct Include For Your AutoIT Scripts
Includes are files that contain prewritten functions for AutoIT. Think of them as functions written into your script that you can call to perform actions for you. You can utilize these files by adding them to your script with the following:
Code:
#include <filename.au3>
Table 1 lists the standard includes that accompany the AutoIT v3 installation.
Етикети:
AutoIT Functions,
AutoIT Includes,
AutoIT Script
Standard AutoIT v3 Includes Table
Include | Description |
Array.au3 | Functions that assist with array management |
AVIConstants.au3 | AVI Constants |
ButtonConstants.au3 | Button Constants |
Color.au3 | Functions that assist with color management |
ComboConstants.au3 | ComboBox Constants |
Constants.au3 | Various AutoIt Constants |
Date.au3 | Functions that assist with dates and times |
DateTimeConstants.au3 | DateTime Control Constants |
EditConstants.au3 | Edit Constants |
File.au3 | Functions that assist with files and directories |
GuiCombo.au3 | Functions that assist with ComboBox |
GUIConstants.au3 | Includes all GUI related constants |
GUIConstantsEx.au3 | Constants to be used in GUI applications |
GUIDefaultConstants.au3 | GUI default control styles |
GuiEdit.au3 | Functions that assist with Edit control |
GuiIPAddress.au3 | Used to create a GUI IP Address Control |
GuiList.au3 | Functions that assist with Listbox |
GuiListView.au3 | Functions that assist with ListView |
GuiMonthCal.au3 | Functions that assist with MonthCal |
GuiSlider.au3 | Functions that assist with Slider Control “Trackbar” |
GuiStatusBar.au3 | Functions that assist with the Statusbar control |
GuiTab.au3 | Functions that assist with the Tab Control |
GuiTreeView.au3 | Functions that assist with TreeView |
IE.au3 | Internet Explorer Automation UDF Library for AutoIT v3 |
Inet.au3 | Functions that assist with the Internet |
ListBoxConstants.au3 | ListBox Constants |
ListViewConstants.au3 | ListView Constants |
Math.au3 | Functions that assist with mathematical calculations |
Memory.au3 | Memory management routines |
Misc.au3 | Functions that assist with Common Dialogs |
Process.au3 | Functions that assist with process management |
ProgressConstants.au3 | Progress Constants |
SliderConstants.au3 | Slider Constants |
Sound.au3 | Functions that assist with Sound files |
SQLite.au3 | Functions that assist access to an SQLite database |
SQLite.dll.au3 | Inline SQLite3.dll |
StaticConstants.au3 | Static Constants |
StatusBarConstants.au3 | StatusBar Constants |
String.au3 | Functions that assist with String manipulation |
TabConstants.au3 | Tab Constants |
TreeViewConstants.au3 | TreeView Constants |
UpDownConstants.au3 | UpDown Constants |
Visa.au3 | VISA (GPIB & TCP) library |
WindowsConstants.au3 | Windows Constants |
Етикети:
AutoIT Constants,
AutoIT Functions,
AutoIT Includes
!Important Note! Variants—Arrays with Differing Data Types
An array using different data types is known as a variant and can contain anything from a number to a Boolean value. Variants are not restricted in AutoIt; however, they are not recommended. Using differing data types in an array—especially arrays within an array—can dramatically decrease the execution speed of your scripts.
Етикети:
AutoIT,
AutoIT Arrays,
Autoit Data Types
Wednesday, March 30, 2011
AutoIT Example 3. Two-Dimensional Array
Code:
A visual representation of Example 3 would be a 2×2 matrix as displayed in Figure 1.
$letter[0][0] = "w"
$letter[0][1] = "x"
$letter[1][0] = "y"
$letter[1][1] = "z"
A visual representation of Example 3 would be a 2×2 matrix as displayed in Figure 1.
Етикети:
AutoIT Arrays,
AutoIT Automation,
AutoIT Examples
Subscribe to:
Posts (Atom)