 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
jaco0646
Joined: 07 Oct 2006 Posts: 2300 Location: MN, USA
|
Posted: Tue Aug 18, 2009 7:19 pm Post subject: Tutorial for Newbies |
|
|
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 Tue Mar 02, 2010 7:30 pm; edited 2 times in total |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 2300 Location: MN, USA
|
Posted: Tue Aug 18, 2009 7:20 pm Post subject: Tutorial for Newbies |
|
|
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). 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:- Hotstrings
- Hotkeys
- Mouse Clicks & Mouse HotKeys
- Variables
- Expressions
- Loops - especially Parsing Loops
- Strings - (e.g. StringMid, StringReplace)
- If,Else statements
- Arrays & Dynamic variables - (StringSplit)
- GoSub & Functions
- GUIs
- Windows Messages
- 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. _________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 2300 Location: MN, USA
|
Posted: Wed Jun 30, 2010 2:12 am Post subject: |
|
|
Syntax for Assignment and Comparison in AutoHotkey
Traditional vs Expression
Assignment:
Traditional 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.
Traditional 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:
Traditional 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%
Traditional If statements cannot perform calculations.
Traditional 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:For this reason, it is usually unwise to use numbers as variable names. _________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|