SciTE4AutoHotkey is a lightweight and easy to use SciTE-based AutoHotkey script editor. AutoHotkey is used to write a script which logs daily food intake while calculating and totaling calories. It builds on the previous To Do List and Address Book apps which use the ListView graphic user interface control. Chapter Fourteen: Fixing the Calorie Count App (Removing Blank Lines). What is AutoHotkey AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of. Export your macros to working AHK scripts. Pulover’s Macro Creator is a Free Automation Tool and Script Generator. It is based on AutoHotkey language and provides users with multiple automation functions, as well as a built-in recorder.
AutoHotkey is a free and powerful tool that allows you to automate almost anything on your Windows computer in any program. Computer Hope uses this tool daily to help answer common questions asked in e-mail quickly and perform other common repetitive tasks. If you do anything daily that requires you to repeat the same actions, we highly recommend using this tool. This page demonstrates some of this program's capabilities.
CautionThis tool can automate tasks in gaming, some online games may consider this cheating and if caught it may result in a ban.
If you want to follow along with this page's examples, please download and install AutoHotkey before following any of these steps. Otherwise, skim this page for a better understanding of the program before downloading and installing it on your computer.
Edit the script
After AutoHotkey is installed to create and edit a script right-click anywhere on the desktop or in a folder, click New, and choose AutoHotkey script. Name the script whatever you want and then right-click the script file and choose Edit the script.
TipIf you plan on always using the same scripts you can also load AutoHotkey at startup, right-click the AutoHotkey icon () in the Windows notification area, and click Edit this script. The default script (AutoHotkey.ahk) opens in your default text editor and allow you to add or change your script. Each time AutoHotkey loads when your computer starts this default script loads this script.
Script basics
Each script in AutoHotkey can also be assigned a keyword (hotstring) or a personalized keyboard shortcut key. When using a keyboard shortcut any shortcut can be used as long as Windows has not already assigned those keys to another task. Each shortcut key can be comprised of any of the following modifier keys and any other letters, numbers, or other keys on the keyboard followed by two colons (::).
- Windows key represented as a '#'
- Alt key represented as a '!'
- Ctrl key represented as a '^'
AutoHotkey includes two example scripts, the first one (as shown in the picture) opens the AutoHotkey web page when you press the Windows Key and Z at the same time. Which can be done now if you have AutoHotkey installed and the default autohotkey.ahk loaded. Otherwise, this line can be added to a new script, saved, and ran to allow this shortcut to work.
Most scripts are more than one line. However, in the above example, it's only one line and needs no additional commands. In the following script example, the script has multiple lines, and as shown, must be finalized with the 'return' command to prevent anything following this script from being executed.
The above script starts with the shortcut key Ctrl+Alt+n, the next four lines are an if else command, which in English translate to 'if an untitled Notepad window exists then make that window active, else run a new Notepad.'
Creating your first script
With your basic understanding of how this program works, lets create your first script to print 'Hello World!' anywhere you want. Move the cursor to the end of your new script file or the default Autohotkey.ahk script file and add the following line.
In this first example, we are not using a shortcut, only the keyword 'hello' to execute the script. Also, because '!' is a modifier key command for the Alt key its been surrounded by curly brackets, which indicates the key, not a command. Finally, this script also contains a comment at the end, which is everything from the semicolon to the end of the line. In AutoHotkey scripts, all text between a semicolon and the end of the line is considered to be a comment. You can use comments to help explain the code in the script.
Any time you make any changes to a script it must be reloaded or run for those changes to work.
To load the script, double-click the script file or right-click the script file and choose Run Script. If you're editing a running script, make sure to reload the script by right-clicking the AutoHotkey icon () in the Windows notification area and choose the Reload This Script.
Once the script is loaded, you should be able to type 'hello' in the following text box and after pressing space or any punctuation the script type out 'Hello World! My first script.'
TipIf you don't want to have to press the space or punctuation, you can add an asterisk between the two first colons.
Next, in the next example, we are creating a script that is executed with a shortcut key. Edit the script and add the following three lines to your script.
After these three lines are added, save the file as the same file name and then reload the script. If done successfully, clicking in the text box below and pressing the Windows Key + F2 would print 'Hello World!' to the screen.
Any shortcut keys can also be added, data can be copied to and from the clipboard, and the script can sleep for any amount of time. Edit the script again and make the following changes to the script created earlier.
In the above example, lines three and four have introduced how keys can be pressed in the script to perform other keyboard shortcuts. The third line is pressing Ctrl+Shift+Home to highlight all text before the cursor, and the next line is pressing Ctrl+C to copy the highlighted text. Anytime a key is pressed down (e.g., {CTRLDOWN}) make sure it is let go with up (e.g., {CTRLUP}), otherwise it remains down and cause problems.
The fifth line introduces a variable and the %clipboard% command which contains anything in your clipboard. With this line, all contents in the clipboard are assigned to the 'example' variable.
The next command is making the example variable all uppercase by using the StringUpper command and assigning the uppercase text back to the example variable. The StringLower command could also be used to make everything lowercase.
Next, the sleep command is a great command for making the script sleep for any length of time. 1000 is equal to 1 second. This command is useful and often necessary if the script has to wait for the computer to open a program or window.
Finally, the last send command adds ' - new hello =' with the hello world now all in uppercase. This revised version of the script can be tested again in the text box.
Scripting the mouse
Although almost anything can be done using keyboard shortcuts, there are still times you may want to click somewhere on the screen. Using the click command, you can click on any location of the screen as shown in the following example. To determine the location of where you want to click, use the Window Spy utility that can be opened by right-clicking the AutoHotkey icon () and clicking Window Spy. As you move your mouse, the 'In Active Window' displays the location of your mouse cursor's current position. Once you've determined where you want to click, add the Click command with the location of where you want the mouse to click.
With this command once Win+F2 is pressed the mouse will click once at 980,381.
Run a program
If you run a program often, it can be open in a script by typing run and the name of the file you want to run. Earlier in this page we gave an example of how to run Notepad by typing 'run notepad' in the script. If you're familiar with the Windows Run, many of the same commands and ways you run a program or open a file work in AutoHotkey. Below are some additional examples of what the run command can do in AutoHotkey.
In the first example, this would open WordPad with the default directory C:My Document, and open the window maximized.
Any Internet URL can be added after the run command to open that web page in your default browser.
Here is another example of the run command, which is sending an e-mail using your default e-mail client and sending the e-mail to [email protected] The subject of the e-mail is 'My Subject,' and the body of the message is 'Body text example.'
Using variables
Like other programming and scripting languages, AutoHotkey supports the use of variables in the script. As seen earlier, we demonstrated copying the clipboard contents to a variable. A variable in AutoHotkey can be either a string or an integer and does not need to be declared like other programming languages.
In our first example, we are using an integer variable to add two numbers together and display the results in a message box.
In the above example, 'example' is our variable name, := is assigning the integer expression as the value of 5+5 (10). Once the variable is assigned, we are using the msgbox command to open a message box and print its value. Whenever you are sending, printing, or assigning a variable it must begin and end with a percent symbol. After saving and reloading the above script, when pressing Win+F2 you should see a message box similar to the example shown on this page.
In the next example, we are assigning the variable a string value, and once again displaying the results in a message box.
In the above example, we are assigning the example variable to 'Nathan' and because it's a string it must be surrounded in quotes. When Win+F2 is pressed this time, the script opens a message box saying 'Hello World! My name is Nathan'.
To have a variable with a string and integer, place the expression outside the quotes, as seen in the following example.
When executed, the message box displays 'Mixed variable is Example: 10'
Conditional statements
Conditional statements are also supported with AutoHotkey and support the operators and (&&), or (||), and not (!). Below are a few examples of how conditional statements can be used.
In the above example, the variable is assigned to 5 and the conditional statement verifies it's equal to 5. Because this is true, the msgbox prints true. If the example value was not equal to 5, the msgbox would have returned false.
You would think after seeing the first conditional statement example that you could put quotes around a string in the variable and conditional statement; however, this will not work. If you want to match a string, surround your expression with parentheses as shown in the following example.
In the above example, if the example variable is equal to hope, print true, otherwise print false. Because the example variable is assigned as 'computer' this script returns false.
Creating a loop
If there is a script that you want repeat, place the script into a loop, as seen in the following example script.
Once the above script is added, and the script re-loaded or run, you should be able to click in the text box and press Win+F2 to print Hello World! five times. The loop can be extended to repeat as many times as you want.
Regular expressions
Like other scripting languages, AutoHotkey also supports the use of regular expressions (regex), which allows you to replace any text within a string with other text. A regex is useful for times you may want to change the formatting of text or remove unnecessary data within a string.
In the example above, the third line with RegExReplace replaces the @ and everything after it with nothing. As a result, the example variable only shows the username account of the e-mail address. When Win+F2 is pressed, the message box displays 'Username is support'.
Additional information
- Visit the AutoHotkey overview for a full listing of available AutoHotkey commands.
Let’s discuss the loop and how to use it in AHK
In this post I try to present looping,
one of AutoHotkey’s basic concepts in a non-programmers way
So I’ll discuss two of the loops available in AutoHotkey.
Once you are clear about these two loop commands,
you can find more in the AutoHotkey documentation /other resources
So remember to check out other loops like:
for-loop and file-reading loop that are also available in AHK to learn how they work.
But now let’s consider a situation where you want to show Hello, World! in a dialog on screen.
More than once, let’s just say five times.
Here is a simple AHK script to do that −
When the above program is executed, it produces a msgbox 5 times with this content −
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
That was simple but:
Let’s considerer another situation
Now you want to write Hello, World! one thousand times.
We can certainly write MsgBox commands a thousand times
However there are many reasons why this would not be optimal.
All programming languages provide a concept called loop,
which helps in executing one or more commands a desired number of times.
All high-level programming languages even provide various forms of loops,
which can be used to execute one or more statements repeatedly.
Let’s write the above AHK script with the help of a loop and later, we will discuss how other loops work
When the above program is executed, it produces the same result as seen before −
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
The above script makes use of a simple loop, which is being used to execute a set of programming statements enclosed within {…}.
A loop statement allows us to execute a command or group of statements multiple times.
All loops in AutoHotkey also set the value of the build in variable “A_index” with the current loop number i.e. if a loop is currently running for the 3th time then A_index will hold the number 3 and on the fourth loop it will hold 4 etc…
The while Loop
The while loop available in AutoHotkey has the following syntax −
The above code can be represented in the form of a flow diagram as shown below −
The following are important points to be noted about a while loop −
- A while loop starts with a keyword while followed by a condition enclosed in ( ).
- Following the while command and condition, you will have the body of the loop enclosed in curly braces {…}.
- A while loop body can have one or more lines of code to be executed repeatedly.
- If the body of a while loop has just one line, then its optional to use curly braces {…}.
- A while loop keeps executing its body until a given condition holds true. As soon as the condition becomes false, the while loop breaks and continues executing from the immediate next statement after the while loop body.
- Let’s write the above AHK script with the help of a while loop and then we will discuss how this loop works
- A condition is usually a relational statement, which is evaluated to either true or false. A value equal to zero is treated as false and any non-zero value works like true.
When the above program is executed, it produces the same result as seen before −
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Here, the computer first checks whether the given condition is true, i.e., if variable “A_index” is less than or equal to 5 or not, if the condition is true, the loop body is entered to execute the given statements.
In our current example we only have a single command in the loop body −
Ahk Script Writer Pastebin
- The Msgbox command, which shows the string Hello World!
After executing all the lines/commands given in the loop body, the computer goes back to while ( A_index = 5) and the given condition, (A_index = 5), is checked again, and the loop is executed again if the condition holds true.
This process repeats as long as the given condition remains true which means variable “A_index” has a value less than 6.
The Loop…Until
![Ahk script writer font Ahk script writer font](/uploads/1/1/8/8/118813163/665053243.png)
A while loop checks a given condition before it executes any statements given in the body part.
AutoHotkey provides other ways to use loop, like Loop…Until that allows executing a loop body first, then checking a given condition. It has the following syntax −
This process repeats as long as the given condition remains true which means variable “A_index” has a value less than 6.
The above code can be represented in the form of a flow diagram as shown below −
If you write the above example using Loop…Until, then it looks like this −
When the above script is executed, it produces the same 5 msgbox’s −
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
The break statement
When the break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.
The syntax for a break statement in AHK is −
A break statement can be represented in the form of a flow diagram as shown below −
Here is a variant of the above script, but it will break out of the loop after showing Hello World!
Three times −
When the above script is executed, it produces the following MsgBox’s −
Hello, World!
Hello, World!
Hello, World!
The continue statement
The continue statement in AutoHotkey works somewhat like the break statement.
Instead of forcing termination, continue forces the next iteration of the loop to take place, skipping any code in between the continue and the closing brace without going through the loop. (this can be thought of as “restarting” the loop and skipping anything that was after the continues location in the body)
The syntax for a continue statement in AHK is as follows −
A continue statement can be represented in the form of a flow diagram as shown below −
A variant of the script above with continue looks like:
Autohotkey Script Writer Download
This will skip showing a MsgBox when A_index has a value equal to 3 −
If you execute the above AutoHotkey script, it shows the following result −
Autoscriptwriter 2
Hello, World! Number: 1
Hello, World! Number: 2
Hello, World! Number: 4
Hello, World! Number: 5
Ahk Script Writer Online
If you’d like to know more about the loop online, I’m happy to help
Autohotkey Script Writing
Let me know what things you’ve used the loop command for…