<

AutoHotkey - Getting Started

Published on
75,552 Points
4,652 Views
19 Endorsements
Last Modified:
Approved
Community Pick
Joe Winograd, Fellow&MVE
50+ years in computer industry. Everything from development to sales. CIO. Document imaging. EE MVE 2015, EE MVE 2016, EE FELLOW 2017.
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to additional resources for EE members who want to learn more.


I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have also answered many questions with a reference to AutoHotkey as a component of the solution. As I was about to write another article with an AutoHotkey program and the how-to-download-and-install paragraph, I decided it would be better to publish a more comprehensive write-up on the process, including some background on the language.


AutoHotkey is a free (in all senses of the word), open source product, published under the GNU GPL (General Public License, Version 2, June 1991). It is a fork of the popular AutoIt language. AutoHotkey started out as a keyboard shortcuts and mouse clicks/movements capability (hence, "Hotkey" in the name), but has been enhanced into a robust programming/scripting language.


AutoHotkey itself has forked several times, with the release at AHKScript.org considered by devotees of the language to be the active/primary branch. Update: Since the initial publication of this article, the ahkscript.org and autohotkey.com domains have been reunited (visiting the former redirects to the latter). If you'd like to learn more about the history of the language, I recommend The AutoHotkey Foundation and Our History pages at its website and the Wikipedia AutoHotkey article.


With a decent computer and Internet connection, the download and installation of AutoHotkey should take less than a minute. At the time of publishing the most recent update to this article, here are the steps:


(1) Visit the AutoHotkey site and click the white-on-green Download button:



(2) This will take you to a download page that shows the current version number and date, with a big white-on-blue button to download the Installer (along with other download options):



(3) Click the Download AutoHotkey Installer button to download the installer (unless you have another need, such as wanting the ZIP file). The exact dialog that you get from this depends on your browser and its settings. For example, you may see something like this:


download-installer.jpg

In any case, run the installer.


(4) If you have UAC on, you will see this:


UAC.jpg


Sidebar: If you're wondering how I captured the UAC dialog box, see my EE article, How to disable the secure desktop when User Account Control (UAC) prompts for elevation.


(5) If it is a new install, clicking the Yes button on the UAC dialog will give you this:


select-version.jpg


The recommended Unicode 32-bit is a good choice for new AutoHotkey users.


(6) If you already have AutoHotkey on the system, it will display the installed version and offer to upgrade it, such as this:


upgrade-install.jpg


Close all running scripts before you click the Upgrade to button, although if you don't, it will warn you:


close-running-scripts.jpg


(7) In a very short period of time (seconds, not minutes), you will see this Installation complete dialog:


installation-complete.jpg


That's it! You now have AutoHotkey installed on your computer. It owns the file extension AHK, which is a plain text file with the program in it. You may use whatever text editor you want to create an AHK source code file, even the built-in Notepad (just be sure to save it as a file type of AHK). Since AutoHotkey is associated with AHK files, double-clicking on one in Windows/File Explorer (or whatever file manager you use) will cause AutoHotkey to run that script.


To get started, let's code the classic Hello World program in AutoHotkey. Open up whatever text editor you want and copy/paste this one line of code in it:

 

MsgBox,0,First AHK script,Hello World


Save the file as HelloWorld.ahk (or whatever you want to call it, as long as the file type is AHK) and then double-click it in your file manager. AutoHotkey will execute it and you'll see this:


Hello-World.jpg


You'll likely use the MsgBox command often, so you may want to study its syntax. In fact, all of the AutoHotkey commands are well-documented, with complete syntax and good examples.


A standard installation of AutoHotkey also installs a compiler, which converts an AHK source code file into a stand-alone executable (an EXE file). These EXE files should run on all versions (and bit levels) of Windows going back to Windows 2000. Indeed, I have run these EXE files on W2K, XP/32-bit, Vista/32-bit, W7/32-bit, W7/64-bit, and W8/64-bit. In addition, I just ran the HelloWorld.exe (created on W7) on the W10/64-bit Technical Preview (Build 10061, the latest release at the time of publishing this article) — it worked perfectly:


HelloWorld-EXE-on-W10-64bit.jpg


The easiest way to compile is to right-click on an AHK file in your file manager and select Compile Script from the context menu:


context-menu-Compile-Script.jpg


For more compiling options, such as selecting a custom icon or compressing the EXE file, you may run the compiler separately (the installer creates a shortcut to Convert .ahk to .exe in the AutoHotkey Program Group):


compiler.jpg


My purpose in writing this article is to provide an easy, quick, yet comprehensive Getting Started  guide to which I can refer EE members. Going into more detail than presented in this article is not necessary, as there is an excellent and thorough AutoHotkey Beginner Tutorial at the AutoHotkey site.


If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe

19
Comment
  • 6
  • 5
  • 4
  • +3
19 Comments
LVL 31

Expert Comment

by:Thomas Zucker-Scharff
Joe,

Thanks for this article, it is sorely needed on on EE.  

Joe was the person who introduced me to AHK when I asked a question about automation here on EE.  Since then I have gone on and automated many functions in one of the daily program I use.  AHK has been my saviour many times over.  Thanks Joe.
0
LVL 60

Author Comment

by:Joe Winograd, Fellow&MVE
You're welcome, Tom, and thanks to you for the kind words and the upvote — both very much appreciated! I'm really glad to hear that you're putting AutoHotkey to good use on a daily basis. Regards, Joe
0

Expert Comment

by:Nirvana
Joe, thanks a lot for this article.. I have just started to use AHK and it is amazing.

I am trying to automate a process where i update fields in a webpage for about 80 forms a day.

the input is in excel and  from there it needs to populated to web page. attaching a sample of excel and web page.

it will be really helpful if you can provide script for this

attached are the sample files of excel and web file

BR
UK
sample.xlsx
Registration-Form.html
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

LVL 60

Author Comment

by:Joe Winograd, Fellow&MVE
You're welcome, Uday. I'm glad you found the article to be helpful.

I do not have the time now to write the entire script for you. However, I can point you in the right direction. The key to the solution is to take advantage of AutoHotkey's native support for Microsoft's Component Object Model (COM). I published an EE article, How To Rename-Move a Batch of PDF Files Based on the Contents of Corresponding Excel Files, providing the source code for an AutoHotkey script that calls COM to retrieve the value in an Excel cell. For example, in the spreadsheet you posted, the last name is in cell B5. Here is a fully functioning AutoHotkey script that retrieves the Last Name:

ExcelFileName:="c:\temp\sample.xlsx"
LastNameCell:="B5"
oWorkbook:=ComObjGet(ExcelFileName)
LastNameValue:=oWorkbook.Worksheets(1).Range(LastNameCell).Value
MsgBox,0,Test AHK COM,Last Name is %LastNameValue%

Open in new window


Simply copy/paste that into an AHK file (with, of course, your sample spreadsheet in the stated location) and the code above will produce this message box:

Test AHK COM call
Do that for all of the values in the spreadsheet (Prefix, First Name, Last Name, Street Address, etc.) and then populate the HTML file with those values. When all of the values have been placed in the HTML file, use the AutoHotkey FileAppend command to write it out (since HTML is a plain text file). Regards, Joe
0

Expert Comment

by:Nirvana
Thanks a ton Joe . will try this out. Thank you again but in future if you think something is useful to me please post.
0
LVL 60

Author Comment

by:Joe Winograd, Fellow&MVE
> but in future if you think something is useful to me please post.

OK, but let me know how you do on your own efforts.
0

Expert Comment

by:Nirvana
What is the best way to learn from your experience should i go through entire learning content of ahk or should I try automate few project and learn by doing?
0
LVL 31

Expert Comment

by:Thomas Zucker-Scharff
I can tell you I learned by getting some help from Joe and more help from Ahkscript.org for a project I was working on.
0

Expert Comment

by:Nirvana
you people are role models...there is a great satisfaction to automate something which was taking hours for someone to doing it in minutes .. will learn by doing.. will definitely need help..more so because.. i do not have any programming experience and with finance background..

A goal without plan is a wish :)
0
LVL 31

Expert Comment

by:Thomas Zucker-Scharff
Learning by doing is the best way in my experience.  Between Joe and ahkscript.org I got help writing a second script that automated a mass  mailings using excel and Outlook.
0
LVL 31

Expert Comment

by:Thomas Zucker-Scharff
0

Expert Comment

by:Nirvana
Thank you every script helps me to learn
0

Expert Comment

by:d0nMaTTi
I've a program which need to log on (windows desktop -program).
I've tried to record (using autoscriptwriter.exe)  but when I run script - it will stop asking  password.
Is it at all possible to set password to other program using autohotkey script

Matti N
0
LVL 60

Author Comment

by:Joe Winograd, Fellow&MVE
Hi Matti,

Yes, an AutoHotkey script can send the password — it can send any sequence of keystrokes. I suspect that the problem is with the code generated by AutoScriptWriter. You'll need to debug that code. Also, I recommend trying Pulover's Macro Creator:
http://ahkscript.org/boards/viewtopic.php?f=6&t=143

I haven't used any script generator myself, but Pulover's gets very good reviews from the AutoHotkey user community. Regards, Joe
0

Expert Comment

by:d0nMaTTi
Thank's. I'll try that
0
LVL 19

Expert Comment

by:Andrew Leniart
Great article Joe. Very helpful.
Sidebar: If you're wondering how I captured the UAC dialog box, see my EE article, How to disable the secure desktop when User Account Control (UAC) prompts for elevation.
I cheat and do it by capturing the entire action in an Oracle Virtual Machine installation from the Host side. The other benefit to that method is that I need not concern myself about ever accidentally showing sensitive files and/or folders when zooming around in Internet explorer while creating video tutorials :-)

Cheers..
0
LVL 60

Author Comment

by:Joe Winograd, Fellow&MVE
Hi Andrew,
Thanks for the compliment — I appreciate it! Your idea sounds like a good one for folks who run virtual machines — thanks for the feedback. Regards, Joe
0

Expert Comment

by:camtz
Excellent. Thanks Joe.
Carlos
0
LVL 60

Author Comment

by:Joe Winograd, Fellow&MVE
You're welcome, Carlos, and thanks to you for the compliment. If you take a moment to click the thumbs-up icon at the bottom of the article, I''ll appreciate it — as you can see, you'll be endorsement #20. :) Regards, Joe
0

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Join & Write a Comment

The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month