Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Eudemons Online > EO Guides & Templates
You last visited: Today at 03:56

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Auto-IT Guide to Programming

Discussion on Auto-IT Guide to Programming within the EO Guides & Templates forum part of the Eudemons Online category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
Auto-IT Guide to Programming

Comi's Autoit guide.

This is not my own work, its a repost from another forum that i felt would be relevant to all here who want to make a start with auto it to make macros and bots. I will however extend on it and add in some relevent things pertaining to the making of bots and macros for Eudemons Online.

First of all Im writing this guide to help people understand the basics of autoit, and end up having a general idea of how to script with au3. Im making this guide with info from me, the autoit help file, the autoit forums, & others.
Be ready to read a lot , and read the same stuff several times if you dont understand. Be ready to do LOTS of tests since its the BEST way to learn this lang IMO.

Best way to used this guide is to go testing each example as they go appearing.

This guide is not ment to be-all and end-all autoit3 guides out there. All autoit3 info is NOT and wont be in this guide as this is a begginer's guide. Already know programming ? Already knew autoit2 or 3 ? Go read the help file.


________________________________________
Introduction


AutoIt v3 is a BASIC-like scripting language designed for automating the Windows GUI. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys).

AutoIt was initially designed for PC "roll out" situations to configure thousands of PCs, but with the arrival of v3 it is also well suited to performing home automation and the scripting of repetitive tasks.


Which in simple's man talk means, that with autoit you can basically do everything that you can do with mouse & keyboard , and much more...

AutoIt has been designed to work on Windows 95, 98, ME, NT 4, 2000, XP and 2003.

________________________________________

Getting autoit v3

In order to use this guide properly you will need autoit.

Find it here URL="http://www.autoitscript.com/autoit3/"]http://www.autoitscript.com/autoit3/[/URL]

Make sure to install it, if you have trouble installing it, coding simply is not for you.

________________________________________

Basics

AutoIt scripts are simple text files that you can edit with notepad or any other simple test editor. Autoit will read those scripts and do what you write step by step.
If you have previous programming knowledge you will find that scriptiong in autoit is extremely easy, therefore also very fun to do.


One of the best new features with AutoIt v3 is the ability to work directly with certain types of Window Controls. Almost everything you see on a window is a control of some kind: buttons, listboxes, edit fields, static text are all controls. In fact Notepad is just one big "Edit" control! Because AutoIt works directly with a control they provide a more reliable way to automate than to just sending keystrokes.


________________________________________
Autoit Window spy

Awesome utility that gives you all the info you might need about a specific window. It will reveal info only about the window you have currently selected. It will also be "always on top", meaning that it will always be on top of other windows.

AutoIt Window Spy allows you to get information from a specified window that can be used to effectively automate it.

If will give the folowing info:

* Window titles
* Text on the window (visible and hidden)
* Window size and position
* Contents of the status bar
* Position of the mouse pointer
* Colour of the pixels underneath the mouse pointer
* Name of the Control underneath the mouse pointer


With the help of AU3Spy you should be automating in no time!

When AU3Spy is running you may want to copy text directly from it using CTRL-C and then paste it into your script to avoid spelling/case errors. This can be difficult when you want to capture pixel/mouse information as it keeps changing! To help with this you can "freeze" the output of AU3Spy by pressing CTRL-ALT-F. Press the keys again to "unfreeze".


CTRL + ALT + F , remember that as since it is very usefull.
________________________________________



spallapiden is offline  
Thanks
5 Users
Old 05/11/2008, 09:57   #2
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
General au3 language reference

The following link will direct you to the auto-it website and specificly the language reference documents.

________________________________________

Types of data

In autoit , to make it simple you have 2 types of data , numeric and string (text) data.

String data
String data is basically text info thats sotred on a variable(explained next). String data always starts and ends with "" or '', even if single or double quotes are inserted in the text it the first and final quotes are the important ones.
For example

variable="hello" , variable will contain hello in it.

variable="comi "not really" rocks" , variable will contain comi "not really" rocks in it.

If you have 2 numeric strings stored and try to do arimetic operations with the autoit will automatically convert them to numeric.

Variables can contain strings of up to 2 billion characters.

Numeric data
Basically numbers, you will use them mostly for internal operations or as counter for multiple things ... ect...

Numbers can be standard decimal numbers like 2, 4.566, and -7.

Scientific notation is also supported; therefore, you could write 1.5e3 instead of 1500.


Numeric & string reference


A variant can contain numeric or string data and decides how to use the data depending on the situation it is being used in. For example, if you try and multiply two variants they will be treated as numbers, if you try and concatenate (join) two variants they will be treated as strings.

Some examples:

* 10 * 20 equals the number 200 (* is used to multiply two numbers)

* 10 * "20" equals the number 200

* "10" * "20" equals the number 200

* 10 & 20 equals the string "1020" (& is used to join strings)[/



& is very important, as it can be used to join string and numberic variables with/or direct data.
Whenever using & the return value will be string.

________________________________________

Variables

A variable is just a place to store data in memory so that it can be accessed quickly. Think of it as a mailbox in memory that you can put information in or take information out of. For example you might create a variable to store the number a user's response to a question, or the result to a math equation.

Each variable has a name (again, similar to a mailbox) and must start with the $ character and may only contain letters, numbers and the underscore _ character.


Here are some example names:



Note that a variable will only hold numeric OR string value, i cant contain both.

Declaring Variables


Variables can be declared in several ways, but ill go with the easy one , or else why would you be reading this tutorial ? For extended info refer to the autoit help.

You can and will declare variables by simply assigning them a value, either string or numeric.
You will use = to assign a value to a variable. You will add a value either directly on the script, via user imput, via .ini or file read or else thru a aritmetic operation. Many many functions in autoit will give RETURN VALUES , you will use variables to obtain them.

Examples, all work:

Code:
=15

="ownage"

 = "good"

= 16 * 3

 = (2 * 2)+5

=InputBox("Question", "what do you want to say?", "", )
(more on these later on)

=" }:p " & " <--- he is a crazy guy"
Macros

AutoIt has an number of Macros that are special read-only variables used by AutoIt. Macros start with the @ character instead of the usual $ so are easy to tell apart. As with normal variables you can use macros in expressions but you cannot assign a value to them.

The pre-defined macros are generally used to provide easy access to system information like the location of the Windows directory, or the name of the logged on user.


Check the help file for a complete list.

________________________________________

Operators

AutoIt has mathematical, logical and comparison operators.

mathematical operators will do a matematic precedure, adding for example.
Code:
2-2=1
3*3=9
Logical operators will do a logic precedure on separate values.
Code:
... 1 NOT 2 ...

if "A" AND "c" are uppercase ....
Comparison operators will compare 2 or more values with eachother.
I
Code:
f = 5 Then (true if  equals 5)
________________________________________

When more than one operator is used in an expression the order in which things happen is controlled by operator precedence. The precedence used in AutoIt is given below. Where two operators have the same precedence the expression is evaluated left to right.


From highest precedence to lowest:

Code:
    * NOT
    * ^
    * * /
    * + -
    * &
    * < > <= >= = <> ==
    * AND OR 



e.g. 2 + 4 * 10 is evaluated as 42:

4 * 10 (equals 40)

2 + 40 (equals 42)
As the * has a higher precedence than + it occurs before the addition.
You can use brackets to force a part of the expression to be evaluated first.

Code:
e.g. (2 + 4) * 10 equals 60.
________________________________________

Operators list

Code:
+ Adds two numbers. e.g. 10 + 20 (equals 30)
- Subtracts two numbers. e.g. 20 - 10 (equals 10)
* Multiplies two numbers. e.g. 20 * 10 (equals 200)
/ Divides two numbers. e.g. 20 / 10 (equals 2)
& Concatenates/joins two strings. e.g. "one" & 10 (equals "one10")
^ Raises a number to the power. e.g. 2 ^ 4 (equals 16)
NOT Logical NOT operation. e.g. NOT 1 (equals 0)
= Tests if two values are equal (case insensitive if used with strings). e.g. If = 5 Then (true if  equals 5)
== Tests if two values are equal (case sensitive if used with strings)
<> Test if two values are not equal.
> Tests if the first value is greater than the second.
>= Tests if the first value is greater than or equal to the second.
< Tests if the first value is less than the second.
<= Tests if the first value is less than or equal to the second.
AND Logical AND operation. e.g. If  = 5 AND  > 6 Then (true if  equals 5 and  is greater than 6)
OR Logical OR operation. e.g. If  = 5 OR  > 6 Then (true if  equals 5 or  is greater than 6)
________________________________________


spallapiden is offline  
Thanks
4 Users
Old 05/11/2008, 10:05   #3
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
Conditional Statements

You will often want to change the flow of your script based on a condition or series of conditions. Is one number bigger than another? Or, does a string contain a certain value?


Conditional statements are available in AutoIt

Code:
If...Then...Else
Select...Case
Both statements are similar and decide which code to execute depending on the condition given. Here is an example of an If statement that pops up a message box if a variable is greater than 10.

________________________________________
If...Then...Else...EndIf

Conditionally run statements.
Code:
If <expression> Then
    statements
    ...
[ElseIf expression-n Then
    [elseif statements ... ]]
    ...
[Else
    [else statements]
    ...
EndIf
If the expression is true, the first statement block is executed. If not, the first true ElseIf block is executed. Otherwise, the "Else" block is executed.

Here is an example of an If statement that pops up a message box if a variable is greater than 10.

Code:
 = 20

If  > 10 Then
    MsgBox(0, "Example", " was greater than 10!")
Else
    MsgBox(0, "Example", " was less than 10")
EndIf
In the example above the expression $var > 10 evaluated to true because the variable was indeed greater than 10. This caused the If statement to execute the first MsgBox line and display "$var was greater than 10!".

________________________________________

Select...Case...EndSelect

Conditionally run statements.

Code:
Select
    Case <expression>
        statement1
        ...
    [Case
        statement2
        ...]
    [Case Else
        statementN
        ...]
EndSelect
If the expression is true the following statements up to the next Case or EndSelect statement are executed. If more than one of the Case statements are true, only the first one is executed.

A Select statement is very similar to the IF statement, but is generally used for situations where you want to test a large number of conditions as it is generally easier to read than than large If/ElseIf type block. e.g.

Code:
 = 30

Select
     Case  > 1 AND  <= 10
         MsgBox(0, "Example", " was greater than 1")

     Case  > 10 AND  <= 20
         MsgBox(0, "Example", " was greater than 10")

     Case  > 20 AND  <= 30
         MsgBox(0, "Example", " was greater than 20")

     Case  > 30 AND  <= 40
         MsgBox(0, "Example", " was greater than 30")

     Case  > 40
         MsgBox(0, "Example", " was greater than 40")
EndSelect

of course Case $var > 20 AND $var <= 30 will be the selected case and the mesage box will return "$var was greater than 20"

________________________________________

Loop Statements

A loop is how you refer to a section of script that you repeat a number of times. You might might want to loop a given number of times or you might wish to repeat a section of script as long as a certain condition is true or false.


The following loop statements are available in AutoIt:

Code:
For...Next
While...WEnd
Do...Until
While (no pun intended) all the statements perform similar functions, they are slightly different and one will usually be more appropriate than another for a given situation.

________________________________________

For...Next

Loop based on an expression.
I dont use this one much really...

Code:
For $<variable> = <start> To <stop> [Step <stepval>]
    statements
    ...
Next

Parameters
variable The variable used for the count.
start The initial numeric value of the variable.
stop The final numeric value of the variable.
stepval [optional] The numeric value (possibly fractional) that the count is increased by each loop. Default is 1.

Important

For...Next statements may be nested. The For loop terminates when the value of variable exceeds the stop threshold. If stepVal or stop is a variable, its value is only read the first time the loop executes.

A For loop will execute zero times if:
start > stop and step > 0, or
start < stop and step is negative

Code:
For  = 5 to 1 Step -1
    MsgBox(0, "Count down!", )
Next
MsgBox(0,"", "Blast Off!")

This will result in 5 message boxes counting from 5 to 1 one after eachother and after the one a message box will come saying Blast Off!

________________________________________

While...WEnd

Loop based on an expression.
Extremely used loop.

Code:
While <expression>
    statements
    ...
WEnd
If the expression is true the following statements up to the WEnd statement are executed. This loop continues until the expression is false.

Important
While...WEnd statements may be nested.
The expression is tested before the loop is executed so the loop will be executed zero or more times.
To create an infinite loop, you can use a non-zero number as the expression.

Code:
 = 0
While  <= 10
    MsgBox(0, "Value of  is:", )
     =  + 1
WEnd

This example loop will start showing a msgbox with "0" and contine goin on adding 1 untill it reaches 10.

________________________________________

Do...Until

Loop based on an expression.


Code:
Do
    statements
    ...
Until <expression>
The statements in between Do and Until are executed until the expression is true.

Important
Do...Until statements may be nested.
The expression is tested after the loop is executed, so the loop will be executed one or more times.

Code:
 = 0
Do
    MsgBox(0, "Value of  is:", )
     =  + 1
Until  = 10
Same result as while, this example loop will start showing a msgbox with "0" and contine goin on adding 1 untill it reaches 10.

________________________________________
spallapiden is offline  
Thanks
4 Users
Old 05/11/2008, 10:10   #4
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
Functions

A function is a section of code that can be called from the script to perform a certain "function". There are two sorts of functions in AutoIt, inbuilt functions and user functions.
You will use a function mostly for code re-use & better script organization.

Inbuilt Functions

There are really usefull, but they are not as flexible as self-made functions. For an Inbuild function list refer to the autoit help file.

User Functions

User functions are declared using the Func...EndFunc statements.

Func...Return...EndFunc
Defines a user-defined function that takes zero or more arguments and optionally returns a result.

Code:
Func functioname ( [ByRef] , ..., [ByRef] )
    ...
    [Return [value]]
EndFunc

The parameters are set by you. You later call the function like any other built-in function.

The ByRef keyword is optional and means: (1) the parameter must a variable, and (2) the variable could be changed by the function. By default, a parameter is passed by value which means that a copy of the parameter's value is manipulated by the function.

Use the Return keyword to exit the function. Unlike built-in functions, user-defined functions return 0 unless another return value is specified.

Arrays can be passed to functions (and returned from them) by simply using the array name without any brackets. Note that function declarations cannot appear inside other function declarations.


Functions can accept parameters and return values as required.

Function names must start with either a letter or an underscore, and the remainder of the name can contain any combination of letters and numbers and underscores. Some valid function names are:

Code:
MyFunc

Func1

_My_Func1
For better organization of the script I usually define the functions at the top of the script.

Examples

Here is an example of using a function to double a number 5 times:
(note that only from Func to EndFunc is the real function)

Code:
 = 10 
For  = 1 To 10
      = MyDouble()
     MsgBox(0, "",  & " doubled is " & )
      = 
Next

Exit

Func MyDouble()
      =  * 2
     Return 
EndFunc
Sample script with three user-defined functions.
Notice the use of variables, ByRef, and Return.

Code:
 = 2
 = 5
msgBox(0,"Today is " & today(), " equals " & )
swap(, )
msgBox(0,"After swapping  and ", " now contains " & )
msgBox(0,"Finally", "The larger of 3 and 4 is " & max(3,4))
Exit

Func swap(ByRef , ByRef )  ;swap the contents of two variables
    Local 
     = 
     = 
     = 
EndFunc

Func today()  ;Return the current date in mm/dd/yyyy form
    return (@MON & "/" & @MDAY & "/" & @YEAR)
EndFunc

Func max(, )  ;Return the larger of two numbers
    If  >  Then
        return 
    Else
        return 
    EndIf
EndFunc

One of my Functions, extremely usefull for logging stuff.


Code:
Func datetime()
   =string(@MIN)
   [email protected]
   =string(@MDAY)
   =string(@MON)
   =string(@YEAR)
   If =00 then
      ="24"
   Else
      =string(@HOUR)
   Endif
    =  & ":" & 
   =  & "/" &  & "/" & 
   = & " --  " & 
   Return ()
EndFunc
add this to a script to test it

Code:
=datetime()
Msgbox(0, "The current date and time", )

________________________________________
Extra usefull info

Although only one statement per line is allowed, a long statement can span multiple lines if an underscore, _, is placed at the end of a "broken" line.

Like for example

Code:
MsgBox(64,"", "This is a rather long line, so I broke it with the underscore, _, character.")

Would be the same as
Code:
MsgBox(64,"", "This is a rather _
long line, so _
I broke it with the _
underscore, _, char_
acter.")

Might not look usefull but in this case for example
(real example)
Code:
IF = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" OR = "error" Then
   MsgBox(48, "Gaiabot by Comi", "Error reading the ini file")
   Exit
Endif

Thats a bit of a mess ... but if scripted like this:
Code:
IF _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" OR _
= "error" _
Then
   MsgBox(48, "Gaiabot by Comi", "Error reading the ini file")
   Exit
Endif
Its MUCH easyer to read , remeber if you script is easy to understand it will be easyer to update/fix/patch it.

________________________________________

The semicolon ( is the comment character. Unless the semicolon is within a string, all text following it is ignored by the script interpreter/complier.


Code:
; The next line contains a meaningful, end-of-line comment
Sleep(5000)  ;pause 5 seconds

Fox example, on the next script lines the green text will be completely ignored when interpreted or compiled. From a real used script...
Note that semicolons are in red just to be remarked.
Code:
;********checks if d2 is running, also check if using d2 or d2loader.*********
=0
If WinExists("Diablo") Then ;norm diablo
=1
Else
If NOT WinExists("D2Loader") Then ;d2loader
MsgBox(48, "MHstarter by Comi", "Could not find Diablo II")
Exit
Endif
Endif
________________________________________

For long extense comments you can use #comments-start .
Similar to the comments in C.
Specify that an entire section of script should be commented out.

Code:
#comments-start
...
...
#comments-end


...
...
Will be completly ignored by the interperter.

The #comments-start and #comments-end directives can be nested.
You can also use the abbreviated keywords #cs and #ce.
Additionally, the directives themselves can be commented out!


Code:
#comments-start
MsgBox(4096, "", "This won't be executed")
MsgBox(4096, "", "Or this")
#comments-end

Comments in general can be very usefull for debugging(searching for errors and polishing the script) since you may ignore a line or sector instead of deleting it. Alos usefull when you are unsure where the error is.

________________________________________

NOTE: You cannot put comments on lines ending with underscores!

For example, this wont work and it will give you a big nice error.

Code:
IF _
= "error" OR _
= "error" OR _
= "error" OR _ ;like omg can i say this here?
= "error" OR _
= "error" OR _ Then

="no errors?"
Endif


spallapiden is offline  
Thanks
3 Users
Old 05/11/2008, 10:18   #5
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
Function Reference

In autoit, there are loads of functions, most of them do unique things but sometimes something done by 1 can be done with a combo of several.

I will only list the most used and not-hard-to-use functions ONLY.
For a FULL funct. list make sure to read the autoit3 help file.

________________________________________
Send

Sends simulated keystrokes to the active window.


The send command, you will use this one to simulate general keyboard use. This function is really versatile, and you will be able to pretty much simulate ANYTHING (keyboard related) with it.


Code:
Send ( "keys" [, flag] )

keys =The sequence of keys to send.
flag [optional] Changes how "keys" is processed:
flag = 0 (default), Text contains special characters like + and ! to indicate SHIFT and ALT key presses.
flag = 1, keys are sent raw.


'!'
This tells AutoIt to send an ALT keystroke, therefore Send("This is text!a") would send the keys "This is text" and then press "ALT+a".
N.B. Some programs are very choosy about capital letters and ALT keys, i.e. "!A" is different to "!a". The first says ALT+SHIFT+A, the second is ALT+a. If in doubt, use lowercase!

'+'
This tells AutoIt to send a SHIFT keystroke, therefore Send("Hell+o") would send the text "HellO". Send("!+a") would send "ALT+SHIFT+a".

'^'
This tells AutoIt to send a CONTROL keystroke, therefore Send("^!a") would send "CTRL+ALT+a".
N.B. Some programs are very choosy about capital letters and CTRL keys, i.e. "^A" is different to "^a". The first says CTRL+SHIFT+A, the second is CTRL+a. If in doubt, use lowercase!

'#'
The hash now sends a Windows keystroke; therefore, Send("#r") would send Win+r which launches the Run dialog box.

You can, if wanted send a specific keypress simlulation.
like

most used:
Code:
{SPACE}
{ENTER}
{ALT}
{BACKSPACE} or {BS}
{DELETE} or {DEL}
{ESCAPE} or {ESC}
There are many more, all usefull. Read the help file.

______________________________________

Send Examples

Will send the Comi rocks keypresses, if in active text bar , will write it.

Code:
="coke is 1337"
Send()
Will send coke is 1337

Code:
Send("ok lets press enter{ENTER}")
Will send ok lets press enter and will prss enter.

Code:
Send("ok lets press enter{ENTER}", 1)
Will send ok lets press enter{ENTER}

There are many ways to use this function, those are the basics. Read the help file.

________________________________________

Mouse Click

Perform a mouse click operation.

So basically, this will emulate the mouseclicks you do with your mouse.

Not a so-simple command, but surely one of the most important ones.

Code:
MouseClick ( "button" [, x, y [, clicks [, speed ]]] )
______________________________________
button
Quote:
The button to click, "left", "right" or "middle".

No big deal on this one, simply put whatever buttong you want to press.
If a user has switched his primary (left) and secondary (right) mouse buttons, a script may not work as you expect(will press inverese keys of what youve scripted). Solution below.

******************************************

Coordinates

x, y [optional] The x/y coordinates to move the mouse to. If no x and y coords are given, the current position is used.

Basically where you will click. Remeber that to get coordinates you will use Autoit·3 window spy.
IMPORTANT!
MouseCoordMode(option) by default will use absolute screen coordinates. You will most likely need to set this au3 option to 0,relative coords to the active window.

Code:
MouseCoordMode(0)

******************************************

clicks

clicks [optional] The number of times to click the mouse. Default is 1.

How many click ull do , usually 1 will do. Its usually better to write the command line twice than use the clicks option.
MouseClickDelay(option) Alters the length of the brief pause in between mouse clicks.
Time in milliseconds to pause (default=10).

******************************************

speed

speed [optional] the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.

Lets say mouse is in position A, and you want to click on B. If you dont set the speed , it will take time for the cursor to move from a to b, once in B it will click. Using default value in this will make your mouseuse script go extremely slow, and can create delay and loop bugs. I EXTREMELY RECOMMEND THE USE OF SPEED AT 0 (instant click).

______________________________________
MouseClick Examples

Code:
MouseClick("left")
Will do a left click wherever the cursor is.

Code:
MouseClick("left", 34, 500, 2)
Double click at coords 34-500

Code:
Dim 
Dim 
;Determine if user has swapped right and left mouse buttons
 = RegRead("HKEY_CURRENT_USERControl PanelMouse", "SwapMouseButtons")

; It's okay to NOT check the success of the RegRead operation
If  = 1 Then
     = "right"
     = "left"
Else ;normal (also case if could not read registry key)
     = "left"
     = "right"
EndIf
MouseClick(, 0, 500, 2)
Exit
^ Fix for the swiched mousekeys.
spallapiden is offline  
Thanks
3 Users
Old 05/11/2008, 10:29   #6
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
Making a GUI

Making a GUI window

Your probably wondering what I mean 'Making a window'. It will come clear.

This tutorial is going to teach you:
-Opening a window
-Using memory, functions and values

Ok, lets get started with making this application:

Firsty, you want to open SciTE. This is what you will write your code in. It displays colours for the Autoit code you enter.

Once SciTE is open, it will look like a new document of notepad (well, sort of). Ok, here is the function to open a window.

Code:
#include <GUIConstants.au3>

GUICreate ( "Title" , Width , Height )   -   This will make a window open.
If you typed this into SciTE, changed the data a bit, it would work. But the window closes. We need it to loop so it stays open.

The looping code is:

Code:
GUISetState ()
While 1
     = GUIGetMsg()
Wend

Basically, what that code says is, "While the window is open, it is looking for a message before it closes. This may not make sense at the moment, but it will once this tutorial is over.

Ok, I'm going to write a basic script to display a window and I'm going to explain it and let you compile it.

Code:
#include <GUIConstants.au3>
GUICreate ( "Bebobox" , 200 , 200 )
GUISetState ()
While 1
     = GUIGetMsg()
   Select
        Case  = 
            ExitLoop
   Endselect
Wend

Ok, I will go through this line by line:
Line 1 : Lets Autoit know we are making a window
Line 2 : Creates a window called Bebobox, 200px by 200px.
Line 3 and 4 : Dont close window. Loop it.
Line 5, 6, 7 and 8 : Complete the loop
Line 9, 10 and 11 : Finish the loop

Copy that code above into SciTE and at the top click File > Save As. Then you want to name it anything ending with '.au3' . Au3 is the ending for source codes in Autoit.

I've posted my code if you don't know what is happening.

Once you have saved the code, find it, right click it, and click 'Run Script'. This will then open the window you made. Have a fiddle about wih it and get used to changing my codes yourself.
spallapiden is offline  
Thanks
1 User
Old 05/11/2008, 10:32   #7
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
A metheod to find and attack a monster.

So, what you need to do is to scan through a range of pixils looking for something specific that only a monster has, and that is the red bar above the name. Auto-IT has a pixil search function and to use it you write code like this,
Code:
$=PixelSearch(200,100,825,600,12059395,5)
$Coords is a variable to hold the return value from the function PixelSearch all variable in auto-it have a $ prefixing them. the values that follow PixilSearch are start_x, start_y, end_x, end_y that determines the range on the screen that it will scan, the next number is a colour, to determne the exact colour you need to use something like photoshop to get a RGB value which you can convert to a hex or decimal value, the number 12059395 is a decimal value for the colour red as scene on my display, this value may vary for you. The last number 5 is a skip value, its the number of pixils to skip per scan, see you check every one is overkill, the red bar is about 15 pixils long, so you only need to hit 1 pixil of the colour 12059395 to get a result, 5 is a fairly accurate and speedy way to scan for the colour.

Anyways, im tired and am going to bed, here is my complete attack function,

Code:
Func Attack()
$=PixelSearch(200,100,825,600,12059395,5)
    If NOT @error Then
        MouseClick("left",+10,+20,1,0)
        Sleep(2500)
	Else
        MoveRandom()
    EndIf
EndFunc ;==> This function searches for the RED monster bar attacks if it finds one, or moves to a new location if there is no monster found.
So what does it do,
1. if searches for the red in the monster bar,
2. it checks to see if $Coords has a value
3. clicks on the monster to begin attacking if $Coords has value
4. waits for a period of time because if it does not pause for a while, you will move on before you killed the monster.
5. if $Coords is not valid, it will move you to another location MoveRandom() is a function call, its a function that you will have to write yourself, there are a number of ways you can do this, have a go at it yourself.

Forums is doing weird shits to my code, replace $ with $Coords
spallapiden is offline  
Thanks
2 Users
Old 05/11/2008, 10:40   #8
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
Metheod of Random Movement

Here is one way to add movement to your macros.

Func RandomMove()
$X=Random(0,1024,1)
$Y=Random(0,690,1)
MouseClick("Left",,,1,0)
Sleep(1500)
EndFunc

So whats it do,

1. Selects a value for the X coord between 0 and 1024
2. Selects a value for the Y coord between 0 and 690
3. Does a left click at the location of X,Y
4. Pauses the macro for 1.5 seconds to allow the char to move to the new location.
spallapiden is offline  
Old 05/11/2008, 10:42   #9
 
elite*gold: 0
Join Date: Sep 2007
Posts: 177
Received Thanks: 35
thanks
mihatud03 is offline  
Old 05/11/2008, 10:44   #10
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
The forums seems to drop of anything that starts with a $ when its contained within a code block, i will have to go back through the above tutorial and fix each location where it has occurred. Sorry for the inconvenience.
spallapiden is offline  
Thanks
1 User
Old 05/11/2008, 11:41   #11
 
elite*gold: 0
Join Date: Nov 2006
Posts: 72
Received Thanks: 30
below are a set of functions for manipulating memory, lets face it, pixel bots can only go so far, after that you need to actually start to manipulate memory, reading values, writing values back etc, these functions will do that for you. Credit is given to those who wrote these functions. i will not put these in code blocks because the forums eat the variable declarations.

#include-once
#region _Mem()
;================================================= =====================
; AutoIt Version: 3.1.127 (beta)
; Language: English
; Platform: All Windows
; Author: Nomad
; Requirements:
; These functions will only work with beta. If you place this
; script in your include folder, you can use these functions
; just as any other function, as long as you put
; "#include <Memory.au3>" in your script (or w/e you name it).
;================================================= =====================
; Credits:
; wOuter:
; These functions are based on his original _Mem() functions.
; They are easier to use and comprehend, IMO. These functions
; are in no way a direct copy of his functions. His functions
; only provided a foundation from which these evolved. The
; biggest changes were made made to _MemRead() and _MemWrite().
; You also no longer need to use _MemCreate() before using
; _MemWrite().
;================================================= =====================
; Additional:
; I've never used _MemRev(), _MemAlloc(), _MemFree(), or _MemText()
; So I did not attempt to revise them in any way and they are not
; included in this script.
;
; Please remember to credit accordingly for any use of these UDF's.
;================================================= =====================


;================================================= =====================
; Function Name: _MemOpen()
;
; Description: Opens the process specified by the Process ID and
; returns the necessary Dll information for reading
; from it's memory.
;
; Parameters:
; $Pid = The Process ID of the program you want to open.
;
; $InheritHandle = [optional] If this value is TRUE, processes
; created by this process will inherit the
; handle. Otherwise, the processes do not
; inherit this handle. Most users will not
; need to alter this parameter.
;
; Returns:
; On Success: Returns an array containing the .dll and an open handle
; to the specified process.
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemOpen($Pid, $InheritHandle = 0x1F0FFF)

Local $Dll[2] = [DllOpen('kernel32.dll')]
Local $OpenProcess = DllCall($Dll[0], 'int', 'OpenProcess', 'int', $InheritHandle, 'int', 0, 'int', $Pid)

If @Error Then
DllClose($Dll[0])
SetError(1)
Return 0
EndIf

$Dll[1] = $OpenProcess[0]

Return $Dll

EndFunc

;================================================= =====================
; Function Name: _MemRead()
;
; Description: Reads the value located in the memory address
; specified by the $Address parameter. You must open
; the process first with _MemOpen()
;
; Parameters:
; $Address = The memory address you want to read from.
; It must be in hex format (0x00000000).
;
; $Dll = The necessary Dll information which is an array returned
; from _MemOpen().
;
; $Type = [optional] The "Type" of value you intend to read.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. For example, if you want to read a
; word that is 15 characters in length, you would use
; 'char[15]' since a 'char' is 8 bits (1 byte) in size.
;
; Additional:
; Values returned are in Decimal format, unless specified as a
; 'char' type, then they are returned in ASCII format.
;
; Returns:
; On Success: Returns the value located at the specified address
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemRead($Address, $Dll, $Type = 'dword')

If Not IsArray($Dll) Then
SetError(1)
Return 0
EndIf

Local $LpBuffer = DllStructCreate($Type)

DllCall($Dll[0], 'int', 'ReadProcessMemory', 'int', $Dll[1], 'int', $Address, 'ptr', DllStructGetPtr($LpBuffer), 'int', DllStructGetSize($LpBuffer), 'int', '')

If Not @Error Then
$Value = DllStructGetData($LpBuffer, 1)
Return $Value
Else
SetError(1)
Return 0
EndIf

EndFunc

;================================================= =====================
; Function Name: _MemWrite()
;
; Description: Writes data to the specified memory address
;
; Parameters:
; $Address = The memory address which you want to write to.
; Must be in hex format (0x00000000).
;
; $Dll = The necessary Dll information which is an array returned
; from _MemOpen().
;
; $Value = The information you want to write.
;
; $Type = [optional] The "Type" of value you intend to write.
; This is set to 'dword'(32bit(4byte) signed integer)
; by default. See the help file for DllStructCreate
; for all types. If you want to write a 'char' type,
; you will use 'char[15]' if it's 15 characters in
; length.
;
; Returns:
; On Success: Returns 1
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemWrite($Address, $Dll, $Value, $Type = 'dword')

If Not IsArray($Dll) Then
SetError(1)
Return 0
EndIf

Local $LpBuffer = DllStructCreate($Type)
DllStructSetData($LpBuffer, 1, $Value, 1)

DllCall($Dll[0], 'int', 'WriteProcessMemory', 'int', $Dll[1], 'int', $Address, 'ptr', DllStructGetPtr($LpBuffer), 'int', DllStructGetSize($LpBuffer), 'int', '')

If Not @Error Then
Return 1
Else
SetError(1)
Return 0
EndIf

EndFunc

;================================================= =====================
; Function Name: _MemClose()
;
; Description: Closes the process which was opened using _MemOpen().
;
; Parameters:
; $Dll = The necessary Dll information which is an array returned
; from _MemOpen().
;
; Returns:
; On Success: Returns 1
; On Failure: Returns 0 and sets error to 1
;================================================= =====================
Func _MemClose($Dll)

If Not IsArray($Dll) Then
SetError(1)
Return 0
EndIf

DllCall($Dll[0], 'int', 'CloseHandle', 'int', $Dll[1])
If Not @Error Then
DllClose($Dll[0])
Return 1
Else
DllClose($Dll[0])
SetError(1)
Return 0
EndIf

EndFunc
#endregion
spallapiden is offline  
Thanks
1 User
Old 02/05/2009, 22:31   #12
 
elite*gold: 0
Join Date: Feb 2009
Posts: 2
Received Thanks: 0
the best on Auto it is its run as function and the ability to easily create Guis
look at:
boern is offline  
Old 02/20/2009, 16:36   #13
 
elite*gold: 0
Join Date: Jun 2008
Posts: 802
Received Thanks: 335
Thanks man, I really value the work. Gr8 post.
DiobloSlayeR is offline  
Old 02/21/2009, 08:47   #14
 
elite*gold: 0
Join Date: Nov 2008
Posts: 21
Received Thanks: 0
zzzzz.... any hack for wr lulu need it plz..
amir123 is offline  
Old 05/16/2010, 21:43   #15
 
elite*gold: 0
Join Date: Mar 2008
Posts: 218
Received Thanks: 134
Code:
#include <GUIConstants.au3>
GUICreate ( "Bebobox" , 200 , 200 )
GUISetState ()
While 1
     = GUIGetMsg()
   Select
        Case  = 
            ExitLoop
   Endselect
Wend
I get error while running this script on line 5. Says "Error: unable to parse line"
Maybe things changed now, considering this guide is old. Very nice though!


revolution263 is offline  
Reply



« HELP | - »



All times are GMT +1. The time now is 03:56.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

BTC: 33E6kMtxYa7dApCFzrS3Jb7U3NrVvo8nsK
ETH: 0xc6ec801B7563A4376751F33b0573308aDa611E05

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2019 elitepvpers All Rights Reserved.