So during Marc Esher's awesome Automation preso at CFUnited I was surprised he didn't talk about Autohotkey. What's Autohotkey you ask? It's a free, open-source Windows application that can add quite a few tools to your automation tool belt. There are some similar tools out there for Mac and Linux which I'll cover in another post. So what can we do with Autohotkey?
- Automate almost anything by sending keystrokes and mouse clicks.
- Create hotkeys for keyboard, joystick, and mouse.
- Expand abbreviations as you type them. For example, typing "btw" can automatically produce "by the way".
- Create custom data-entry forms, user interfaces, and menu bars.
- Remap keys and buttons on your keyboard, joystick, and mouse.
- Convert any script into an EXE file that can be run on computers that don't have AutoHotkey installed.
This week I'll try to cover at a basic level everything you can do with Autohotkey at a basic level. So what are you waiting for! Go download it! http://www.autohotkey.com/ Installation is straightforward. Run the executable, keep the defaults and follow the prompts. The first time you start Autohotkey, it will prompt and ask if you'd like to create a sample script ( autohotkey.ahk ) in your My Documents folder.
Once Autohotkey is started you will notice a new icon in your taskbar (green box with big H). You can interact with Autohotkey via a right-click on the icon. From here you can edit, reload, pause and exit from Autohotkey.
So now let's experiment and see what Autohotkey does. If everything is setup correctly you should be able to hit WIN+Z (windows key) and your browser should fire up and display the Autohotkey site. Now open up Notepad. Before you head for the Start menu button, try this instead: CTRL+ALT+N. Notepad should fire up. Now we can navigate over and open up the autohotkey.ahk file (remember it was created in My Documents).
This file is heavily commented but the main section we are interested in are:
This simple line breaks down as follows:
#z - simple means when you hit WIN+Z - let's do something. RUN - means we're going to well, run something - in this case it's a URL www.autohotkey.com And since we're passing in a URL - Windows launches our default browser and takes us to the Autohotkey site.
Simple! Lets look at the next script:
^!n:: IfWinExist Untitled - Notepad WinActivate else Run Notepad return
The next example is a bit more complicated but I think any good ColdFusion programmer should be able to read through this and understand what's going on...
^!n = CTRL+ALT+N IfWinExist - simply examines the running applications for one with a title of "Untitled - Notepad". If that exists then it will grab the focus and display it, if not it will start Notepad.
I have several keys setup to launch my frequently used programs. No start menu, no keyboard shortcuts to a launcher where I have to type in "CF Builder". I simply hit F6 to fire up CFBuilder. F7 fires off Oracle SQL Developer:
;F6------------------------------ SC040:: Run C:\eclipse-bolt\eclipse.exe -vm "C:\Program Files\Java\jre6\bin\javaw" vmargs -Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m return ;F7------------------------------ SC041:: Run C:\Program Files\Oracle\sqldeveloper\sqldeveloper.exe return
In this case the SC041:: are simply shortcuts for special keys on my Microsoft keyboard correlating to F6/F7.
Tomorrow we'll look at using Autohotkey to replace text!Go Top