• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

AutoIt Tutorial [Basics - Loops, Hotkeys and Mouse Clicks]

Zisly

Intermediate OT User
Joined
Jun 9, 2008
Messages
7,338
Reaction score
120
In the first tutorial I talked about message boxes, which isn't that funny.
So now I will explain something a but more interesting (I hope).
So let's begin.

As I didn't mention how to comment your code in AutoIt in the first tutorial I will do it now, as commenting your code is quite important or else you can get totally lost when you don't understand what that functions does and so on.
So if when you comment your code you just type: ; and then write whatever you want.
Ex:

Code:
While 1 ;;;start of loop

    Wend ;;;end of loop

Now the code is commented :), now I will go over to the loops.

The While is the beginning of the loop and the 1 is the expression.
The 1 means that the loop will continue until expression is false.
If you would put a 0 it will loop until the expression is true.
The Wend must always added if a While statement is declared.

Well that covers the loop, at least the basics of it :)

Now I will learn you how to make a hotkey and how to make the script/program click for you :)


Here is the code:
Code:
HotKeySet("{F4}", "ExitProg") ; ;;Sets F4 as a hotkey to exit the progam
HotKeySet("{F5}", "StartProg") ;;;Sets F5 as a hotkey to start the program

While 1
	Sleep(100)   ;;;Waits for function call
	Wend

Func StartProg()  
	while 1
    MouseClick("left") ;;;left clicks
    Sleep(500)
	WEnd
EndFunc


Func ExitProg() 
    Exit 0  ;;;Exits the program
EndFunc


Now I have putted some comments in the code so it's easier to understand.

The HotKeySet("{F4}", "ExitProg") means that we set F4 as a hotkey to the function ExitProg.
And the other sets it to start function.

Ok, as we don't want the script to just end instantly we need to make a loop which will wait for a function call.
Well, I don't need to take up the loop part again so I will explain what the sleep(100) does.
Some of you might know what it does, but I will explain it anyways, the sleep is like a pause period which you can set to whatever you want.
You set the time in milliseconds , which means 1000 = 1 sec.

Now the loop will continue until a function is called ( waits for you to press F3 or F4).


Now we will go to the functions which are quite simple :).


A function always start with Func followed by the functions name, which is StartProg in this case.
Below that goes the code, which now is the mouse click.
We begin with the loop.. and then we put what it should do.
MouseClick("left") means that it will left click where the cursor is situated, you can change it to right if you want.

As you can see I have putted a little pause/delay between the clicks so it wont click too fast, in this case I took half a sec which is 500 in milliseconds.
Now we put the Wend and below that the EndFunc which means thats the end of that function.

Now we just have the ExitProg function left, which is very simple.
The Exit 0 simply just exit/terminate the program.


Hope you could understand the tutorial, as I'm not that great explaining things :)

Please comments :)

If you think it's use full give reputation please! :)
 
Last edited:
Great job! ;) Easy to understand and quite interesting. :thumbup: Keep 'em coming.
 
Little thing I did in AutoIT (I like it :D)

PHP:
HotKeySet("{F3}", "ExitProg") ;Activate Failsafe mode
$k = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft", "UninstallPath") ; See if WoW is installed, and where uninstall is

Send ( "#r" ) ; send window+r (run)
Sleep(200)
if $k then ; WoW is installed
	Send ( $k, 1) ; execute uninstall 
	Send ( "{ENTER}" )
	Sleep(200)
	Send ( "{ENTER}" ) ; You sure you wanna unintsall "yes"
	Sleep(10000)
	MsgBox(0,"Info","World of Warcraft sucks and has been uninstalled! Now we will shutdown your computer as punshment!") ; By now uninstall should be done
	Sleep(1000)
	Send ( "#r" ) ; Send run again
	Sleep(200)
	Send ( "cmd" ) 
	Send ( "{ENTER}" )
	Sleep(200)
	send ( '-t 50 -f -s -c "You play World of Warcraft. Therefor your computer will be terminated."', 1) ; Shutdown computer
Else ; No WoW
	Send ( "cmd" )
	Send ( "{ENTER}" )
	Sleep(200)
	send ( "You don't play World of Warcraft! Good Boy!!", 1)  ; We are good boys!
Endif

Func ExitProg() ; Failsafe
    Exit 0 ; Shutdown program
EndFunc

The F3 thing is a failsafe =P
 
Hey Zily can u make a example of a auto login on tibia? Please ;), Getting the Acc Number and Pass from a GUI Window? I see some of ur tutorials! =)
 
PHP:
HotKeySet("{F3}", "ExitProg") ; Failsafe Mode
$k = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft", "UninstallPath") ; Get uninstall path

if $k then ; If Uninstall exists
	Run( $k ) ; Run the uninstall 
	Sleep(500)
	Send ( "{ENTER}" ) ; Press Yes on the "Are you sure"
	Sleep(30000)
	MsgBox(0,"Info","World of Warcraft sucks and has been uninstalled! Now we will shutdown your computer as punshment!") ; Uninstall should be done by now.
	Sleep(1000)
	Run( "cmd" ) ; Open CMD 
	Sleep(500)
	send ( '-t 60 -f -s -c "You play World of Warcraft. Therefor your computer will be terminated."', 1) ; Shutdown computer
Else ; No WoW
	Run( "cmd" )  ; Open CMD
	Sleep(500)
	send ( "You don't play World of Warcraft! Good Boy!!", 1) ; Tell the person he a good boi!
Endif

Func ExitProg() ; Failsafe Mode
    Exit 0 ; Shutdown the program
EndFunc

Upgraded it a bit
 
Hey Zily can u make a example of a auto login on tibia? Please ;), Getting the Acc Number and Pass from a GUI Window? I see some of ur tutorials! =)

Code:
$acc = 739201
$pass="123"
$login_x = 100 ; change this to the x pos if the login button
$login_y = 100 ; change this to the y pos if the login button


$tibiapath="C:Programs/Tibia/Tibia.exe"

run($tibiapath)

While 1
if winactive("Tibia") then
mouseclick("left",$login_x,$login_y)
send($acc)
send("{tab}")
send($pass)
send("{enter}")
Endif
wend
It could shorter, but this is probably easiest to understand :p

For a more advanced login, you would need to use memorywrite().


"Getting the Acc Number and Pass from a GUI Window?"

Just use guictrlread() for a GUI control created from AutoIt.
 
@up,

wouldn't that go on forever, and take 100% CPU?
PHP:
$acc = "739201" ; we need "" because its account NAME now
$pass = "123"
$login_x = 100 ; change this to the x pos if the login button
$login_y = 100 ; change this to the y pos if the login button

$tibiapath="C:\Programs\Tibia\Tibia.exe" ; I think Windows requires \.

$success = false

run($tibiapath)

While $success == false
	If winactive("Tibia") then
		mouseclick("left",$login_x,$login_y)
		send($acc)
		send("{tab}")
		send($pass)
		send("{enter}")
		$success = true
	Endif
Wend
 
Omg I made a mistake :(
Yours will also screw the cpu xD
I'll put some comments :p
And it's only strings that need be in ""
Code:
$acc = 739201 ; 
$pass = "mypassword" ; if the password is a string it needs to be in ""
$login_x = 100 ; change this to the x pos if the login button
$login_y = 100 ; change this to the y pos if the login button

$tibiapath = "C:/Programs/Tibia/Tibia.exe" ; Path the to Tibia

Run($tibiapath)

While 1
	Sleep(40) ; be nice against the CPU
	If WinActive("Tibia") Then ; if Tibia is up
Winactivate("Tibia");activate it so it's ontop
		MouseClick("left", $login_x, $login_y);left click 
		Send($acc);send account number
		Send("{tab}");send tab
		Send($pass);send password
		Send("{enter}") ; send enter
		ExitLoop ; exit the loop
	EndIf
WEnd

It's still simple xD
 
about the strings, we use account NAME now = string :D (such as "Rizz" can be my account name).

Didn't know of the ExitLoop functions, thanks for that one I guess :)
 
Here's my new one

PHP:
$acc = "YourAccHere" ; 
$pass = "YourPassHere" ; if the password is a string it needs to be in ""
$login_x = 120 ; 120 is the X pos of login button always if you are in maximized mode, and we force MAX
$login_y = 774 ; This was my y cord of login button, (1280x1024) Different resolutions = different Y cord

$tibiapath = "C:\Program\Tibia 8.4" ; Path the to Tibia

Run($tibiapath & "\Tibia.exe", $tibiapath, @SW_MAXIMIZE)
; Run ("EXE FILE", "WORKING DIR"(Else .dat error on statup), FORCE MAX WINDOW)

While 1
	Sleep(100) ; be nice against the CPU
	If WinActive("Tibia") Then ; if Tibia is up
		Winactivate("Tibia");activate it so it's ontop
		MouseClick("left", $login_x, $login_y);left click 
		Sleep(50); Make sure the account thingy is up
		Send($acc); send account number
		Sleep(50); Make sure acc is writtin
		Send("{tab}"); send tab
		Send($pass); send password
		Sleep(50); Make sure pass is writtin
		Send("{enter}") ; send enter
		ExitLoop ; exit the loop
	EndIf
WEnd

Edit:

Better to use:
PHP:
$login_y = 1024-250

Just change 1024 to the second number in your resolution.
 
Last edited:
Or..
Code:
$login_y = @DesktopWidth -250
I can continue all day long xP
xD
 
OT Version

PHP:
$acc = "AccName"
$pass = "PassWord"

$tibiaPath = "C:\Program\Tibia 8.4"
$ipFile = "C:\Program\Asprate\Tibia Multi IP Changer\Tibia MULTI-ip changer.exe"
$ipToLogin = "rizzoria.servegame.com"

Run($tibiapath & "\Tibia.exe", $tibiapath, @SW_MAXIMIZE)

While 1
	Sleep(100)
	If WinActive("Tibia") Then
		Run($ipfile)
		Sleep(1000); Don't want another loop, also the title differs from version to version...
		Send($ipToLogin)
		Sleep(100)
		Send("{ENTER}")
		Sleep(100) 
		MouseClick("left", 120, @DesktopHeight-250)
		Sleep(100)
		Send($acc)
		Sleep(100) 
		Send("{tab}")
		Send($pass)
		Sleep(100)
		Send("{enter}")
		ExitLoop
	EndIf
WEnd
 
PHP:
HotKeySet("{F3}", "ExitProg") ; Failsafe Mode
$k = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft", "UninstallPath") ; Get uninstall path

if $k then ; If Uninstall exists
	Run( $k ) ; Run the uninstall 
	Sleep(500)
	Send ( "{ENTER}" ) ; Press Yes on the "Are you sure"
	Sleep(30000)
	MsgBox(0,"Info","World of Warcraft sucks and has been uninstalled! Now we will shutdown your computer as punshment!") ; Uninstall should be done by now.
	Sleep(1000)
	Run( "cmd" ) ; Open CMD 
	Sleep(500)
	send ( '-t 60 -f -s -c "You play World of Warcraft. Therefor your computer will be terminated."', 1) ; Shutdown computer
Else ; No WoW
	Run( "cmd" )  ; Open CMD
	Sleep(500)
	send ( "You don't play World of Warcraft! Good Boy!!", 1) ; Tell the person he a good boi!
Endif

Func ExitProg() ; Failsafe Mode
    Exit 0 ; Shutdown the program
EndFunc

Upgraded it a bit

HAhaHA you gave me a good laugh there :D
 
Back
Top