AutoHotkey Community

It is currently May 26th, 2012, 8:27 pm

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Tutorial for Newbies
PostPosted: August 18th, 2009, 7:19 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
By popular demand, here is my advice on learning to script with AutoHotkey, extracted from the original topic Tutorial for Newbies. Please leave any comments there.

I’ve also created a sequence of quizzes based on the material in the AutoHotkey Help File and organized according to this tutorial. There are around 10 questions for each section, and most of the answers are found directly in the AHK documentation. These quizzes should cover the important sections of the help file, and hopefully will aid in the learning process by making you think about what you’ve read. Presenting the material in this way might turn on the proverbial light bulb for some people that don’t quite get there by passive reading alone. At least, that’s what I hope.

The zip file, which you can download below, contains each quiz in INI format along with an AHK script to administer the quizzes (if you don’t want to just read the INIs). The script will give your score at the end of each quiz and allow you to review incorrect answers. I’ve added a copy of this tutorial and a few notes as well. Of particular importance is the file named Traditional vs Expression. It explains the two different methods of assigning and comparing variables in AHK.

Have fun, and Good Luck on the quizzes!

>DOWNLOAD<

Note: for more tutorials, see the list on the AutoHotkey Wiki.


Last edited by jaco0646 on March 2nd, 2010, 7:30 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Tutorial for Newbies
PostPosted: August 18th, 2009, 7:20 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Tutorial for Newbies

As a person who started using AHK having absolutely zero programming experience (never taken a class or read a book on computers in my life), I will give you my 2 cents on learning it.

I think exploring the forum works great if you have even a little bit of background in this area. If, like me, you have none, I would learn it in the following order (this is how I would do it if I had to do it over again). :P My reasoning here is that for a person starting from scratch, you need to learn concepts before learning commands, and the forum is geared more towards commands.

First read the Tutorial, the Scripts page, and then the FAQ. Afterwards, I would recommend learning concepts in the following order:
  1. Hotstrings
  2. Hotkeys
  3. Mouse Clicks & Mouse HotKeys
  4. Variables
  5. Expressions
  6. Loops - especially Parsing Loops
  7. Strings - (e.g. StringMid, StringReplace)
  8. If,Else statements
  9. Arrays & Dynamic variables - (StringSplit)
  10. GoSub & Functions
  11. GUIs
  12. Windows Messages
  13. DllCall
The first 3 you will not necessarily use very often once you become proficient with the program; but they are the easiest to comprehend and implement. Everything from Variables through GUIs is what I would consider the "core" of the program that you will use repeatedly to write virtually all of your scripts with. Windows Messages and DLLCalls are the advanced techniques that are the most powerful but most complicated. The average user will probably never have the need and desire to master these two.
Of course this list is not set in stone, and you may be learning multiple items at once (for example you may want to scratch the surface of GUIs right away), but I think all of the items are important to learn about if you plan to use AHK more than a few times, and I tried to arrange them in an order that would be most logical and systematic.

When you're wondering how to accomplish a specific task in AHK, remember that most of the commands have a common naming scheme to identify what they do. For example:

Commands dealing with files start with File.
Commands dealing with windows start with Win.
Commands dealing with text start with String.

Similarly:

Commands that retrieve data from somewhere contain Get.
Commands that apply data to somewhere contain Set.

Combining the two previous structures, we have commands like:

FileGetSize - Retrieve the size of a file.
WinGetTitle - Retrieve the title of a window.
StringGetPos - Retrieve the position of a piece of text inside a larger piece (like a sentence in a paragraph).

FileSetTime - Apply a new Time Stamp to a file.
WinSetTitle - Apply a new title to a window.
SetTimer - Apply a new Timer, which is a command or group of commands that run at timed intervals.


Good Luck, and remember that nobody was born knowing any of this. It takes time.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2010, 2:12 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Syntax for Assignment and Comparison in AutoHotkey

Commands vs Expressions


Assignment:

Command assignment =
Everything to the right of the = sign is considered literal text.
Variables to the right must be enclosed in percent signs. %MyVariable%
The = sign cannot perform calculations.

Command assignments are never necessary. They are merely convenient for assigning literal text because double quotes can then be omitted.

Expression assignment :=
Everything to the right of the := operator is considered an expression.
Literal text must be enclosed in double quotes. "literal text"
Expressions can perform calculations.

You may intersperse literal text with variables and calculations using the := operator.

For example:
Code:
nam := "Expression 1:"
var := nam "two plus two equals" 2+2 "."
MsgBox, %var%
The contents of %var% will be: Expression 1:two plus two equals4.

Note that since I did not add enough spaces into the literal text or use the A_Space variable in the expression, the output is not spaced correctly.

Note also that using the = sign to create the nam variable would've been easier since I could've omitted the double quotes then.


Comparison:

Command comparison If var = value
Everything to the right of the comparison sign is considered literal text.
Variables to the right must be enclosed in percent signs. %MyVariable%
Command If statements cannot perform calculations.

Command comparisons are never necessary. They are merely convenient for comparing literal text because double quotes can then be omitted.

For example:
Code:
If var = literal string
If var = 4
If var = %MyVariable%
If var = ;<--compare to blank value
If var ;<--boolean
Wrong: If var = 2+2

Expression comparison If (var = "value")
Everything to the right of If is considered an expression.
Literal text must be enclosed in double quotes. "literal text"
Expressions can perform calculations.

For example:
Code:
If (var = "literal string")
If (var = "4")
If (var = MyVariable)
If (var = "") ;<--compare to blank value
If (var) ;<--boolean
If (var = 2+2)


Note that numbers will not be mistaken for variables even if double quotes are omitted, so the following works fine:
Code:
If (var = 4)
For this reason, it is usually unwise to use numbers as variable names.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group