PDA

View Full Version : Autoit Tutorial!


Mr.Llama
11-05-2005, 02:43 AM
I'm not sure if anyone here uses autoit (it was semi-popular on blizzhackers), but here's one that I've used in the past (on my website):
Intro/Msgbox Lesson

It's here! And anyone can use it as long as they have Windows! Let's celebrate! Alright. First, you need to download it. You can download it Here Or if that doesn't work you can copy and paste this into your browser ----> http://www.autoitscript.com/autoit3/downloads.php Make sure you do the full instalation that includes AutoItX. Now that it's ready, open up notepad. Or go to start --> Run --> Type in "notepad.exe". This is a pretty simple language and no prior coding experience is required! So, to answer a few questions. What can this do? It can make GUI's (like your notepad), make message boxes, move the mouse, type keys (but they don't make them go down :P) and a few other things.

To save your script as an AutoIt document all you have to do is save it as 'Whateveryourscriptnameis.au3' notice the .au3. Every time you save something as that it will be an AutoIt document. Once you save it as that you can edit it again by right clicking and left clicking 'edit script' or 'open as...' then you'd click notepad. Now, at some point (soon) I reccomend editing (but really looking) at the examples they have. To find them go to start --> All Programs --> Autoit v3 --> Examples. Run one of them. Look at the script. Remember a key part. Now continue to do this with all 9. You may learn something. Remember, anything with the --> ; <-- In front of it will not be read by the computer. It is only used to keep track of what's going on. (It will be very useful when making long programs) Now for the first program.

;This will create a message box

Msgbox(0,"Title", "This is text inside the message box.")

Now save this as --> AutoItTest.au3 <--. When you run this it will bring up a small message box. Now when I say 'line code' it will refer to the code part. The line code! It will usually follow a certain format. Usually when there is some soft of text that the person actually sees, it is usually in these --> "YOU WILL SEE THIS" <--. And every statement (the things in between the commas --> , <-- . is separated by the comas. This will happen every time. And after the title (the first part) it will be followed by a ( and ended with a ). And remember you should always have the AutoIt Help open when you're coding! Because even I forget and need to look at it. Now back to the message box.

The zero after the ( means the flag. The zero means just an Ok sign in the message box. The title is the part at the top. The text inside is surprisingly the text inside the message box.

Sleep and Send

The send and sleep line code's are even simpler than the msgbox lesson. (In fact I think I should've had these as our first lesson)... Oh, well :P. Sleep is a command that you will use A LOT. Possibly even more when you're more experienced. It looks like this:

Sleep(5000)

It is very simple huh! What it does is it stops the program for a certain amount of time. The biggest thing to remember is that 1 = one-Thousandth of a second! So 5000 is really only 5 seconds. So if you're making something wait a day get your calculator out! So type in your time in seconds and add 3 zeros.

The send command is very simple as well. Here is an example. (it will type in your notepad document)

Send("Thanks for reading my tutorial{!}")

All this will do is type what was there. But notice the exclamation point. It is surrounded by these --> { } <--. There are special keys that need those to work. The special characters are !, #, +, ^, {, and }. And for an enter key press you need this --> {ENTER} <--. (Check the Autoit Help section 'Send' for more details. And I forgot to mention once the Autoit Help is open always be in the index tab. It is easier to navigate and get around.

Run

The 'run' command is also very usful. Try running this:

Sleep(1000)

;This wil run notepad

Run("notepad.exe")

Sleep(1000)

;Will type in some text

Send("This encompasses all that we learned!")

Sleep(1000)

;Will create a congrats message box

MsgBox(0,"Kudos", "Great work! Keep it up! And this box wil exit automatically in 6 seconds.",6)

This does do all that we learned!

MouseMovement

Now we've reached the juicy part! You will soon be able to manipulate the mouse! There is another tool called the 'Autoit Window Info'. Open that and click anywhere behind it on the screen. It will give the coordinates for your cursor and more things that we will probably use later. Try running this:

MouseMove(151,183)

MouseMove(293,237)

MouseMove(352,124)

That should move your mouse to 3 different points on your screen. It is also pretty simple. MouseMove(X coordinate, Y coordinate) If you want an exact point. Like to click on something you use the Autoit Window Tool. To freeze the display or make it go again, press ctrl-alt-f all at the same time. Then copy the numbers down into your script. (The window is pretty self explanatory) If you want the mouse to click where it currently is you do:

MouseClick("left")

But if you want it to move and click somewhere you can do:

MouseClick("left", X coordinate, Y coordinate)

Now you can try to make a script that uses all of these. Now one more thing to teach you is how to hide the tray icon. When you run a script look at the bottom right hand side of your screen. It will always be there. Unless you put this at the beggining of your script:

#No TrayIcon

MsgBox(0, "Title", "Text")

Now if you notice it's gone! Yay!

Loops

Loops are just things that the program will come back to. Like a circle. It can be as easy or complicated as you want. In fact, all loops do is shorten code. Except for one type of loop that is endless unless you make it exit with another kind of command called hotkeyset. An endless loop looks like this:

Run("notepad.exe")

While 1

Send("Haha{!} This is endless{!}{!}{!} And will apear every second!")

Sleep(1000)

WEnd

By looking at this program you can easily expand an make something annoying that you cannot escape out of... But to escape for now just right click the icon on the bottom-right hand side and click exit. And if you don't want to run it... That's fine with me. There is also another kind of loop called an 'if' loop. However, I have not explained the next lesson. So I will teach that one later and the inputbox now.

InputBox

The inputbox is something that allows the person who runs the program to type something in and the script will 'remember' it for later use. Try this:

$Age = InputBox("Question", "How old are you?")

Sleep(1000)

Run("notepad.exe")

Sleep(2000)

Send("You are this many years of age:")

Send($Age)

Sleep(1000)

By looking at the script there are many things that I need to cover. For one thing the $Age part. Anything with a dollar sign ($) in front of it is a variable. A variable is stored in the scripts memory and can be used later if needed. Before continuing there is one thing missing, but it isn't there for a reason... Look before continuing! If you noticed that there are no " surrounding the $Age, you were right! Why aren't they there? Well, if in the send line above, if I put the $Age in the " it would type the -> $Age <-- instead of the answer to the question. Now moving on to something similar to the Inputbox...

Yes and No message box

This is very similar to a normal message box, but it has the answers 'yes' and 'no'. The answer is also stored, and uses the If, EndIf loop. I will give a decent example here:

$answer = MsgBox(4, "IQ", "Are you smart?")

If $answer = 7 Then

MsgBox(0, "Yes and No", "You are stupid!")

Exit

EndIf

If $answer = 6 Then

Msgbox(0, "Yes and No", "You think you're smart... But you're really not! _

HAHAHAHAHA!")

Exit

EndIf

So, It's the same function as the Inputbox, but slightly different. The first part --> If <-- That is the starting point for the loop. So, I'll translate the script. "If the answer to the question is no then say you are stupid! Then exit. But if they say yes then bring up a box that says You think you're smart... But you're really not! _ HAHAHAHAHA! Then exit. The If $answer = 7 Then (do the bottom part). Exit Endif. What it does is check the $answer to see if it's equal to seven. (And if you didn't know 7 means the no answer). And the if $answer = 6 is the same thing basically except 6 = yes. And there is one thing that may not look farmilliar. it's the _ . What it means is that you're able to press enter and skip a line down without messing up the code. If you don't want to you never have to use it. But I like to keep my code in a certain way so it's easy for me to read.

This concludes part 1 of the tutorial

The next tutorial that you may expect is... well i'm not sure yet. But I will most likely add to this!

If this is helpful to someone or you want me to add. I may.

c0ik
11-05-2005, 10:31 AM
Very usefull and easy to understand! I was looking for a prog like this since quite a while! Thanks!

Silvernoma
11-05-2005, 04:32 PM
Good tutorial, looking forward seeing more tutorials like that! good job!

WatchPaint
11-13-2005, 05:25 AM
Dude I think this is awesome. I've always wanted to make a simple little popup thing. Now i have! Yay! :D

First off, how would I make it pop up lets say, 10 times? Like the counter in the examples folder. Where it pops up and when u exit it, another pops up, then another, then another... Or lets say you press "OK" and it leads to another popup after that. Thanks.

I like your tutorial, Please make more! Cya

gevorgkhc
11-13-2005, 01:47 PM
Dude I think this is awesome. I've always wanted to make a simple little popup thing. Now i have! Yay! :D

First off, how would I make it pop up lets say, 10 times? Like the counter in the examples folder. Where it pops up and when u exit it, another pops up, then another, then another... Or lets say you press "OK" and it leads to another popup after that. Thanks.

I like your tutorial, Please make more! Cya

i no u wanted a response from Mr.llama but anyway.....

ok, it's really simple. first we declare a variable and assign it to 0:

Dim $i ; i like explicit declaration
$i = 0 ; assign it to zero


Then we must create a message box loop with the While statement (u can use any other loop u want tho)


While $i <= 10 ;While statement
MsgBox(0, "Number:", $i) ;Message Box
i = i + 1 ;i dont know if 'i++' will work in autoit
WEnd ;End of while statement


and there u go, here's the full thing :) :

Dim $i ; i like explicit declaration
$i = 0 ; assign it to zero

MsgBox(0, "LOOK!", "Hey look! I can count to 10!!") ;a little thing i added :)

While $i <= 10 ;While statement
MsgBox(0, "Number:", $i) ;Message Box
i = i + 1 ;i dont know if 'i++' will work in autoit
WEnd ;End of while statement

carrierz
11-13-2005, 03:54 PM
AutoIt -> Sucks.com

gevorgkhc
11-13-2005, 04:57 PM
AutoIt -> Sucks.com

w/e, it's a good language for beginners

WatchPaint
11-14-2005, 08:17 PM
I like autoit...very very nice for begginers. Hey, so if i wanted to make a script, blah blah blah. If i wanted to open like Aim instant messanger when i open it, what do i type in the script. I know notepad is Run("notepad.exe") or somethin...

gevorgkhc
11-14-2005, 08:24 PM
depends on where u installed it. i.e. if i installed it in "C:\Program Files\AIM" then the command would be:

Run("C:\Program Files\AIM\aim.exe")

WatchPaint
12-03-2005, 02:15 AM
Hey, another question from me, yeah i know, sad... Ok, what if i were to create a script that when i play it, (open it, w/e) It does a shut down, or restart.? How would i do that?

Also, is there any way to have the program/script/ whatever you created, to automatically open all by its self?

gevorgkhc
12-03-2005, 02:24 AM
prolly

Shell("shutdown -s") for shutdown and Shell("shutdown -r") for restart

i forgot if Shell was the run cmd..............w/e....

WatchPaint
12-06-2005, 05:29 PM
Hey, is there any websites with any other codes, etc? I would like to know how to do more.

wonly
12-14-2005, 04:47 PM
yeah its a nice tut but its a mix of a few languages so if and when they do learn some other language it will only confuse them they should start with an actual language such as pascal it old and out-dated but its better then some of everything mixed

umm i have a link that has tuts on pascal and u can download Scar which is their program

http://www.kaitnieks.com/

simple and they have many tuts on how to use it

mongolo89
02-20-2006, 01:06 PM
I've got a question to autoit. Is where a way to send a key to an application without activating/maximizing it?
I want to make a script for winamp

Func NextSong()
$title = WinGetTitle("")
Sleep(100)
WinActivate("Player Window")
Send("b")
sleep(100)
WinActivate($title)
EndFunc

This is a little part of my code but with this it just minimizes and then maximizes back to the window before

firemouse
02-20-2006, 01:08 PM
Very nice tutorial!

winston
06-01-2007, 10:01 PM
Thx To A Thread Starter. Really Usefull Tutorial For Nubs Like Me ^_^ Thx.

Sveiningos
06-08-2007, 04:32 PM
Uhm, i found 1 error in your last example while running it,

Should be

$answer = MsgBox(4, "IQ", "Are you smart?")

If $answer = 7 Then

MsgBox(0, "Yes and No", "You are stupid!")

Exit

EndIf

If $answer = 6 Then

Msgbox(0, "Yes and No", "You think you're

smart... But you're really not!")

Msgbox(0,"HAHA!", "HAHAHAHAHA!")

Exit

EndIf


Instead of

$answer = MsgBox(4, "IQ", "Are you smart?")

If $answer = 7 Then

MsgBox(0, "Yes and No", "You are stupid!")

Exit

EndIf

If $answer = 6 Then

Msgbox(0, "Yes and No", "You think you're smart... But you're really not! _

HAHAHAHAHA!")

Exit

EndIf


;) ;)

But anyway, Thanks for a great tutorial! :D :D

Wokin
08-20-2007, 06:22 PM
This tutorial is good. AutoIt reminds me of ACTool.

MagicOPromotion
05-23-2009, 11:48 AM
Im looking for a good tutorial for making textured/blended backgrounds in Illustrator. I can make good lighting, gradients, brushing, blending, etc. in Photoshop, but not so much in Ill.
Thanks