Register for your free account! | Forgot your password?

You last visited: Today at 03:07

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


AutoHotKey tutorial

Discussion on AutoHotKey tutorial within the CO2 Guides & Templates forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
(1) Contents:
(04/05/2007)
(page1/post#1) Contents
(page1/post#1) Introduction
(page1/post#1) Information
(page1/post#2) What you need and how to use it
(page1/post#3) First window
(page1/post#4) Adding more elements
(page1/post#5) Simple input/output
(page1/post#13) Using edit as dinamic text
(page2/post#17) If / else
(page2/post#18) Using hotkeys
(page2/post#20) Getting pixel color and coords
(page3/post#42) Reading and writing into a .ini file


(2) Introduction:
I'm going to use this topic to add samples and codes about AutoHotKey, this post is made for those who want to learn an easy language to create macros or even bots.
Every sample will have a download with the compliled file.
I'll be adding more samples every day and using this first post as a content table.

(3) Information:
Download files are just optionals.
All files will be on .rar format.
To come
+combobox
+radiobutton
+checkbox
+creating tabs
+creating a menu
+searching pixels
+reading and writing into a .ini/.txt file
+deleting/creating files
+combined samples
+some more lol



hieitk is offline  
Thanks
3 Users
Old 05/05/2007, 03:18   #2
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
(4) What you need and how to use it:
4.1 Downloading the program:
First you will need to download AutoHotKey.
You can download the program .
Or go to the website and then to download section.

After installing you will find AutoHotKey on your menu like the one on my picture.
The most important here is:
AutoHotKey Help File: << very helpful xD
Convert .ahk to .exe: << compiler

4.2 Where to write the codes:
What I like about autohotkey is that you can write the code in any text editor, for example I use NOTEPAD, once you have the code ready on NOTEPAD or any text editor save it with the extension .ahk* (AutoHotKey file)

So everytime I give an example code you will have to copy it into NOTEPAD and save it as .ahk or just use the one I give on the download file.

If you make double click on the file .ahk you will be able to test it inmediatly without compilation.

4.3 Creating the .exe file:
If you want to share what you create you can make an executable file out of the .ahk file.
Go to the menu and click on Convert .ahk to .exe, a new window will appear, on source (script file) browse for your .ahk* file and then press convert. Then it will create and .exe file on the same directory of the .ahk file.

*note: you can also work with .txt format and even compile from .txt to .exe but I recmmend to work in .ahk because that way you can test what you are doing everytime by double click on the file. If you work with .txt you will have to complie the file everytime you want to test.

4.4 Another way to create the .exe file:
If you make right click over the .ahk file you&#39;ll see on your menu 3 new options added after installing AutoHotKey.
These are:
Run Script: is the same as double click
Compile Script: create the .exe file
Edit Script: open a text editor
Attached Images
File Type: gif post-108-1178327894.gif (4.4 KB, 288 views)


hieitk is offline  
Thanks
2 Users
Old 05/05/2007, 03:20   #3
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
(5) First window:
5.1 Introduction:
First we&#39;re going to learn how to create a basic window, what is called the GUI (graphical user interface), buttons, text input, checkboxes are part of the GUI as well.
After we know the basics about this we&#39;ll strart with the interaction with the user and variables.

5.2 An empty window:
First open NOTEPAD and copy the next code into it, save it as a .ahk file and double click to see the result.
Quote:
; empty window sample

Gui, Show , w260 h100, Window title

return

GuiClose:
ExitApp
Now is time to explain whats all that xD
Well let&#39;s see part by part:
-------------------------------------------------------
Code:
; empty window sample
This is a comment, to write a comment just use ;, the comments are really useful, they make easier for you to remember the structure of the code or what a line of code is doing.
-------------------------------------------------------
Code:
Gui, Show , w260 h100, Window title
This is the creation of the window itself, w260 is the width of the window and h100 the height and Window title is uhmm well, the title of the window xD
We&#39;re going to use this code always so don&#39;t forget it.
(You can go to AutoHotKeyHelp to see more options for the window like the position in the screen)
-------------------------------------------------------
Code:
return
this line is here only to avoid the program to keep to with the next line, if you remove this line the program will keep reading the code and will Exit the application because of the code ExitApp
-------------------------------------------------------
Code:
GuiClose&#58; 
ExitApp
Here we&#39;re telling the program that once the user click on the "X" to close the window it has to do that xD
Try removing this line and ull see that if you click on the "X" the window won&#39;t close.
We&#39;re going to use this code always so don&#39;t forget it.
-------------------------------------------------------

Well, that&#39;s our first window. Pretty simple huh, try changing the width, height and title ^^
Attached Files
File Type: ibf post-108-1178337179.ibf (205.7 KB, 173 views)
hieitk is offline  
Old 05/05/2007, 03:22   #4
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
(6) Adding more elements:
6.1 Introduction:
On this section we&#39;re going to learn how to add a few more elements like text, buttons and edit (useful to text entry)

6.2 The code:
First open NOTEPAD and copy the next code into it, save it as a .ahk file and double click to see the result.
Quote:

; window with more elements

Gui, Show , w110 h100, Window title

; here you have a text, button and edit
Gui, Add, Text, x10 y10 w90 Center,text here
Gui, Add, Edit, w90 h19 x10 y30 vFIRSTEDIT Center, input here
Gui, Add, Button, x10 y52 w90 h20 vFIRSTBUTTON ,press me


return

GuiClose:
ExitApp
Well, I guess you can see some familiar things and also some new ones, lets take a look
-------------------------------------------------------
Code:
; window with more elements
Comment again, you can put all the comments you want, try not to abuse of them.
-------------------------------------------------------
Code:
Gui, Show , w110 h100, Window title
Again creating the window, this time is a bit smaller ^^
-------------------------------------------------------
Code:
; here you have a text, button and edit
another code =P
-------------------------------------------------------
Code:
Gui, Add, Text, x10 y10 w90 Center,text here
here we&#39;re creating a text, x10 is the X position (horizontal) from the left, that means it will start 10 pixel form the left, y10 the same but vertical and w90 is the with of the space for this text.
(You can go to AutoHotKeyHelp to see more options like color)
-------------------------------------------------------
Code:
Gui, Add, Edit, w90 h19 x10 y30 vFIRSTEDIT Center, input here
Wow, this one is useful, Edit is an entry (or dinamic display) of text. We have the same options x/y/w/h and then vFIRSTEDIT, this mean that the name of the variable in this edit is FIRSTEDIT, in this way we can use the value of the text or change it by using that name.
Don&#39;t worry about that now, we&#39;ll see an example later.
-------------------------------------------------------
Code:
Gui, Add, Button, x10 y52 w90 h20 vFIRSTBUTTON ,press me
This one is useful too, again x/y/w/h options and the name of the variable is FIRSTBUTTON. In a button more important that the name of it is the action or function that will call once pressed. In this example if u press the button nothing happen because we&#39;re not calling any function.
-------------------------------------------------------
Code:
return

GuiClose&#58; 
ExitApp
Same as on the other example ^^
-------------------------------------------------------

Try changing some values, make the window bigger and place the elements in different positions by changing the x/y values, you can always check AutoHotKeyHelp to learn more about these elements and their options.

AutoHotKey have a lot more elements like checkbox, combobox, radio buttons, tabs, menus, etc...
We&#39;re going to see those later, lets learn how to use these first =P
Attached Files
File Type: ibf post-108-1178328161.ibf (205.9 KB, 52 views)


hieitk is offline  
Old 05/05/2007, 03:25   #5
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
(7) Simple input/output :
7.1 Introduction:
Here we&#39;ll create a simple sample that will calculate the double of a number.

7.2 The code:
Open NOTEPAD and copy the next code into it, save it as a .ahk file and double click to see the result.
Quote:

; simple input/output

Gui, Show , w210 h100, Double

; basic elements
Gui, Add, Text, x20 y10 w90 Left,Input a number
Gui, Add, Edit, w50 h19 x20 y30 vNUMBER Left,
Gui, Add, Button, x100 y30 w90 h20 vMYBUTTON gDOUBLE ,Calculate double

return

DOUBLE:
{
Gui, Submit, NoHide
double := 2*NUMBER
msgbox,,Result, The result is %double%
return
}

GuiClose:
ExitApp
Like always, let&#39;s take a look at this
-------------------------------------------------------
Code:
; simple input/output
A comment to remember what the program is about.
-------------------------------------------------------
Code:
Gui, Show , w210 h100, Double
Creating the window with the title Double
-------------------------------------------------------
Code:
; basic elements
Another comment
-------------------------------------------------------
Code:
Gui, Add, Text, x20 y10 w90 Left,Input a number
Just a text so the user can tell what to do. Left is the alignment, you can also use Right or Center
(You can go to AutoHotKeyHelp to see more options)
-------------------------------------------------------
Code:
Gui, Add, Edit, w50 h19 x20 y30 vNUMBER Left,
This is the edit where the user is going to input the number, see after the last "," there is no text so it will appear empty.
-------------------------------------------------------
Code:
Gui, Add, Button, x100 y30 w90 h20 vMYBUTTON gDOUBLE ,Calculate double
Here we have the button, this time we see something new here (gDOUBLE), this means that after you press the button it will make the program go to the subrutine called DOUBLE.
So in general to call a subrutine from a button (or even a text) you should write gNAME_OF_THE_SUBRUTINE
-------------------------------------------------------
Code:
return
To avoid the program keep reading down there =P
-------------------------------------------------------
Code:
DOUBLE&#58;
{
Gui, Submit, NoHide
double &#58;= 2*NUMBER
msgbox,,Result, The result is %double%
return
}
Here we have a subrutine called DOUBLE, the way to create a subrutine is
NAME_OF_THE_SUBRUTINE:
{
what the subrutine will do
}

So let&#39;s see what this subrutine does, first we have:

Gui, Submit, NoHide

This will send the values, when you input something into the Edit the value of NUMBER wont change inmediatly so you need the Submit command to send the new values to the variables.
After this line of code the variable NUMBER will adopt the value the user wrote into the edit.


double := 2*NUMBER

Here we are giving a new variable called double the value of 2*NUMBER.
The way to assign variables is (:=) or (=)

(You can go to AutoHotKeyHelp to see the differences between using = or := )


msgbox,,Result, The result is %double%

Here we are creating a message box to display the result, the usage of msgbox is:
MsgBox , Options, Title, Text, Timeout
In this case I left options empty, the title is Result and the text is The result is %double%, timeout is empty too.
If you are wondering what are those % symbols the answer is, in order to write a variable into a message box you need to write the name of the variable between % (%name_of_the_variable%)
We&#39;ll use those symbol to call variables in other cases too but for lets learn how to use it here.

-------------------------------------------------------
Code:
return
Here we&#39;re telling the program to return after doing the subrutine.
-------------------------------------------------------
Code:
GuiClose&#58; 
ExitApp
Same as usual, to let the user close the window by pressing the "X".
-------------------------------------------------------

May seem complicated but is just a matter of getting used to the language.
Ill be adding more samples tomorrow.
Attached Files
File Type: ibf post-108-1178328328.ibf (206.0 KB, 43 views)
hieitk is offline  
Thanks
2 Users
Old 05/05/2007, 05:10   #6
 
elite*gold: 0
Join Date: Jun 2006
Posts: 31
Received Thanks: 1
wow... thanks for this guide&#33;&#33;

AutoHotKey is a little more complex than autoIt but it is similar to the c++ syntax, I am already familiar with this type of syntax so I hope I can learn fast

+k
AvatarOfMight is offline  
Old 05/05/2007, 09:31   #7
 
elite*gold: 0
Join Date: Oct 2006
Posts: 248
Received Thanks: 22
Great, I will try to make some programs in AutoHotKey.
And +k.
bombica23 is offline  
Old 05/05/2007, 09:55   #8
 
elite*gold: 0
Join Date: Apr 2007
Posts: 110
Received Thanks: 0
this is awesome ... thanks
88slowpoke88 is offline  
Old 05/06/2007, 00:37   #9
 
elite*gold: 0
Join Date: Oct 2006
Posts: 320
Received Thanks: 59
cool, i havent read any of it, but knowing hieitk, its good :P

the most background with automatic stuff is macro express, i made like 2 bots, one for automaticly pressing right click on met, then pressing ok, i made one for jumping thru teh lotto and pressing OK and everythieng, it ownt T_T took me like 40 minutes to figure out the "play till T = T1" XD

or it was somthing like that anyway, but its a lil better then no experiance

Anythieng i make and i think i like maybe ill post the link
- but maybe im getting 2 far ahead of myself lol
im more into hacking, even tho im not good at even that, but yea - im working on it :P
Tinytox is offline  
Old 05/06/2007, 02:13   #10
 
elite*gold: 0
Join Date: Jun 2006
Posts: 31
Received Thanks: 1
Hi
I was trying to make a mining bot with this guide and I found out that you need to get the color codes of the ores and other stuff many times... I made a program to get the color code and I thought that it could be useful for someone... hehe.

Get Color Code This one Includes a simple GUI, not necessary but i was bored... lol
Quote:

Gui, Show , w220 h100, GetColor
Gui, Add, Text, x10 y10 w150 Left,Welcome to GetColor
Gui, Add, Text, x10 y70 w200 Left,press ctrl+alt+c to know the color at which your mouse is located

^&#33;c::
MouseGetPos,PosX, PosY
PixelGetColor, c,&PosX&,&PosY&
MsgBox The color is "%c%"


return

GuiClose:
ExitApp


Simple code Without GUI

Press ctrl+alt+c to get the color code
Quote:
^&#33;c::
MouseGetPos,PosX, PosY
PixelGetColor, c,&PosX&,&PosY&
MsgBox The color is "%c%"
You can copy and paste the code into notepad/Word/ any text editor and save it as an AutoHotKey file (.ahk) and then open it .

I will post later my mining bot (when I am done with it)... just as an example for learners since there are more than enough mining bots already in this forum hehe.
AvatarOfMight is offline  
Thanks
1 User
Old 05/06/2007, 02:26   #11
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
xD nice code man
thats a useful tool to get pixel colors =P
ill be teaching that but later, first some more simple samples before going into pixelcolors
hieitk is offline  
Old 05/06/2007, 02:35   #12
 
elite*gold: 0
Join Date: Oct 2006
Posts: 320
Received Thanks: 59
OOOH&#33;&#33;&#33;

i just got the best **** idea ever&#33;

the three of us (or others too&#33 if we all got good at it we could like.. make the next COtobo O_o

that would be PIMP

(he just mentioned mineing bot so ya :P)

hmmm... i read most of it, i will need to read it like 5X, mostly i was just interested in seeing the creations and playing with em a bit : Give us a assignment :P&#33;&#33;&#33;

tell us the width and hight, then make us creat somthing, im still n00b at it, but it lookz fun&#33;
Tinytox is offline  
Old 05/06/2007, 03:09   #13
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
(8) Using edit as dinamic text :
8.1 Introduction:
In this sample we&#39;re going to use the Text as button and also an Edit to display the result togheter with a message box.
In this sample most of the lines are the same as the previous sample so I&#39;ll only explain the new ones.

8.2 The code:
Open NOTEPAD and copy the next code into it, save it as a .ahk file and double click to see the result.
Quote:

; edit as dinamic text

Gui, Show , w200 h100, Double

; basic elements
Gui, Add, Text, x10 y12 w80 Right,Input a number
Gui, Add, Edit, w65 h19 x95 y10 vNUMBER Left,
Gui, Add, Text, x60 y38 w90 cBLue Left gDOUBLE,calculate double
Gui, Add, Text, x10 y62 w80 Right,Result
Gui, Add, Edit, w65 h19 x95 y60 vRESULT ReadOnly Left,

return

DOUBLE:
{
Gui, Submit, NoHide
double := 2*NUMBER
msgbox,,Result,The result is %double%
GuiControl,, RESULT, %double%
return
}

GuiClose:
ExitApp
Like always, let&#39;s take a look at this
-------------------------------------------------------
Code:
; edit as dinamic text

Gui, Show , w200 h100, Double

; basic elements
Gui, Add, Text, x10 y12 w80 Right,Input a number 
Gui, Add, Edit, w65 h19 x95 y10 vNUMBER Left,
These are almost the same first lines as on the previous sample, creating the window, adding a text telling the user to Input a number and then creating the Edit where the user can write a number, the name of the variable is NUMBER
-------------------------------------------------------
Code:
Gui, Add, Text, x60 y38 w90 cBLue Left gDOUBLE,calculate double
This is interesting, instead of using a button to call the subrutine DOUBLE we are using a text, to do that just write gNAME_OF_THE_SUBRUTINE, you can call subrutine from differents elements not only buttons and text but also checkbox, radio button and... we&#39;ll see that later.
Another new thing here is the option cCOLOR, in this case the color is Blue.
-------------------------------------------------------
Code:
Gui, Add, Text, x10 y62 w80 Right,Result
Just a normal text to let the user know that the other little box is to display the result.
-------------------------------------------------------
Code:
Gui, Add, Edit, w65 h19 x95 y60 vRESULT ReadOnly Left,
Now this is the Edit I&#39;ll use as a dinamic text display, what I want is to display the result here so I write ReadOnly so the user can&#39;t write text in this Edit but only read xD
And this is important, the name of the variable is RESULT, we&#39;ll use this to change the value. Now is empty.
-------------------------------------------------------
Code:
return
As usual ^^
-------------------------------------------------------
Code:
DOUBLE&#58;
{
Gui, Submit, NoHide
double &#58;= 2*NUMBER
msgbox,,Result,The result is %double%
GuiControl,, RESULT, %double%
return
}
Now we are at the subrutine again =P the first 5 lines are the same as in the last sample, the new line is:
GuiControl,, RESULT, %double%
This is to change the value of the Edit called RESULT, in this case the new value we are giving to it is the variable double, thats why is between the % symbols.
The structure is:
GuiControl,, NAME_OF_THE_VALUE, VALUE_TO_REPLACE

-------------------------------------------------------
Code:
GuiClose&#58; 
ExitApp
As usual.
-------------------------------------------------------

8.3 Excercise:
Now is time for you to try something.
The code GuiControl can be used to change the value of some gui elements like text, edit and buttons.
Try adding something to this code, what I want is that when someone input a number and press Calculate double beside displaying the result you have to change the text Input a number for Input Another

8.4 Excercise&#39;s result:
Try not to read this until you try, even if you dont make it the effort of thinking will help you a lot.

First since the GuiControl require a name of the value you&#39;ll have to give one to the text. Like this:
Code:
Gui, Add, Text, x10 y12 w80 vNAME_OF_THE_VALUE Right,Input a number
And then add into the subrutine the GuiControl line:
Code:
GuiControl,, NAME_OF_THE_VALUE, Input another
And thats is for now ^^
Attached Files
File Type: ibf post-108-1178413797.ibf (206.1 KB, 25 views)
hieitk is offline  
Old 05/06/2007, 03:24   #14
 
elite*gold: 0
Join Date: Oct 2006
Posts: 320
Received Thanks: 59
AHHH A DAY TO REMEMBER&#33; MY FIRST AHK CREATION&#33;

Quote:
; the window itself

Gui, Show , W100 h100, TheTrial

; my button&#33; no function yet
Gui, Add, Text, x28 y15 w 100 h100 center, Perfect&#33;
Gui, Add, Edit, w80 h20 x10 y30 vFIRSTEDIT center, Yes, its real
Gui, Add, Button, x10 y60 w80 h35 vFIRSTBUTTON ,you want to press me&#33;


return

GuiClose:
ExitApp
But its VERY VERY basic :/ im working on getting l33t at it, its just not a 1 day thieng 4 me lawl

hieitk , one reqest tho, could you make a post with ALL the definitions and "codes" for this?

Thx if so, if not i understand as always,
Tinytox is offline  
Old 05/06/2007, 03:29   #15
 
elite*gold: 0
Join Date: Mar 2007
Posts: 608
Received Thanks: 357
Quote:
Originally posted by Tinytox@May 6 2007, 03:24
AHHH A DAY TO REMEMBER&#33; MY FIRST AHK CREATION&#33;

Quote:
; the window itself

Gui, Show , W100 h100, TheTrial

; my button&#33; no function yet
Gui, Add, Text, x28 y15 w 100 h100 center,* Perfect&#33;
Gui, Add, Edit, w80 h20 x10 y30 vFIRSTEDIT center, Yes, its real
Gui, Add, Button, x10 y60 w80 h35 vFIRSTBUTTON ,you want to press me&#33;


return

GuiClose:
ExitApp
huahua very good man =P
Nice some ppl is learning from this, right now ill be adding if/else ^^
and then using hotkeys and then pixels =D

Keep it up Tinytox


hieitk is offline  
Reply


Similar Threads
[HELP]Autohotkey
06/11/2011 - AutoIt - 8 Replies
Hallu, elitepvpers! ichh habe gaanz kur ne frage, wo ich es echt nich raffe, habe schon sufu benutzt und gegoogelt, aber nix gefunden, außer die normale anleitung auf english, die ich iwie nich raffe; kann mir wer bei autoit in diesen"noob" script autohotkey einbauen, damit der bot wenn ich auf F7 klicke automatisch beenden! hier der "noob" script! while 1 sleep(500) mousemove(1191,109,0) sleep(200) mouseclick("right") sleep(200) mousemove(1235,186,0)
AutoHotKey Help
01/17/2009 - General Coding - 1 Replies
Hi, Im having trouble with making a background macro for a game called ConquerOnline, refer to this thread . If anyone can help, I would really appreciate it.
AutoHotKey Help?
12/06/2007 - CO2 Main - Discussions / Questions - 11 Replies
I have Read the "Help" File but still cant figure out how to make a macro that works on client 1 while playing on client 2. Any ideas or codes for this :confused: I'm working on a macro that heals/pots/sits/med/stig/dc/area to macro etc. Pretty much it will play the game for u :D
Help with AutoHotKey
03/24/2006 - CO2 Main - Discussions / Questions - 3 Replies
Hey everyone i need some help. does anyone know how to write a command where you hold down ctrl while mouse clicking? all i&#39;ve managed to do so far is make it click ctrl, let go, then mouse click. anyone know the codes to how i can do them both together? thanks. shadowHacker



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


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

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