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.
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.