Saturday, August 17, 2019

AutoIT - Basics with Example


1. MsgBox


#include <MsgBoxConstants.au3>

MsgBox($MB_SYSTEMMODAL,"Process Identifier...",@AutoItPID,5)
Send("{ENTER}")

ConsoleWrite("Enter key is pressed..")
Send("{ENTER}")

MsgBox($MB_SYSTEMMODAL,"Script Name..",@ScriptName,5)
Send("{ENTER}")

MsgBox($MB_SYSTEMMODAL,"Script Full Path",@ScriptFullPath,2)
Send("{ENTER}")

MsgBox($MB_SYSTEMMODAL,"Script Directory",@ScriptDir,6)
Send("{ENTER}")

MsgBox($MB_SYSTEMMODAL,"Script Line Number",@ScriptLineNumber,5)
Send("{ENTER}")

2. Variable


Global $first,$second,$third,$fourth

$first = 100
$second = 125
$third = $first + $second
$fourth = 1250

Local $res = $fourth % 2
MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $res' & @CRLF & @CRLF & 'Return:' & @CRLF &  $res) ;### Debug MSGBOX
ConsoleWrite("$fourth % 2" & $res)

If $second > $first Then
MsgBox(0,"Second is greater than First","Second is " & $second)
EndIf

MsgBox(0,"Result","$first + $second = " & $third)

3. Array


#include <String.au3>

$Source = BinaryToString(InetRead("https://www.youtube.com/watch?v=IeH5iKfI8DY&list=PLNpExbvcyUkOJvgxtCPcKsuMTk9XwoWum"),1)
$FirstChunks = _StringBetween($Source,'content="','">')

For $a In $FirstChunks
ConsoleWrite($a & @CRLF)
Sleep(1000)
Next

Global $Array[10],$Variable

$Array[0] = 0
$Array[1] = 123
$Array[9] = "Finish"
$Array[19] = "Success"

For $a = 0 To 9
ConsoleWrite($Array[$a] & @CRLF)
Next

For $a = 0 To (UBound($Array) - 1)  ;9
ConsoleWrite($Array[$a] & @CRLF)
Next

For $a In $Array
ConsoleWrite($a & @CRLF)
Next

4. InputBox


Global $name

$name = InputBox("SignUp - User Info","Enter your name")

MsgBox(0,"Registered User Info","Thank you for typing name into system and your username is " & $name)

5. If-Else


Global $buttonPressed

$buttonPressed = MsgBox(4,"Select Choice","Press Yes or No")

If $buttonPressed = 6 Then
MsgBox(0,"You have selected","You have pressed YES button!")
ElseIf $buttonPressed = 7 Then
MsgBox(0,"You have selected","You have pressed NO button!")
EndIf

6. Do-While and For loop


Global $first,$second,$third,$fourth

$first = 1
$second = 5

Do
MsgBox(0,"Text",$first)
$first += 1
Until $first = 5


While $first <> 5
MsgBox(0,"Text",$first)
$first += 1
WEnd

For $a = 1 To 10  ;Step + 1
MsgBox(0,"Number",$a)
Next

For $a = $first To $second   ;Step + 1
MsgBox(0,"Number",$a)
Next


7. HotKey Set


HotKeySet('h','HotKey1')
HotKeySet('p','HotKey2')
HotKeySet('x','ExitProgram')

While 1
Sleep(50)
WEnd

Func HotKey1()
ConsoleWrite("The Hotkey was presseed.!" & @CRLF)
EndFunc

Func HotKey2()
MsgBox(0,"This hotkey worked","This hotkey was pressed")
Run('notepad.exe')
EndFunc

Func ExitProgram()
Exit
EndFunc

No comments:

Post a Comment