Windows Scripting With AutoHotKey (AHK) v1.0

Prerequisites: 

Basic understanding of the windows environment
Some programming experience useful but not necessary

I am sure, like me, most of you have to do repetitive tasks in windows daily. If we were in a *nix environment, writing a quick script can save you tons of time. Why not do the same inside of windows? Well a few years ago while I was working support for a fortune 500 company. One of the other techs introduced me to AutoHotKey (referred to as AHK from here on out) to automate some tasks we found ourselves preforming often. So I am going to pass this information on to SX crew in hopes that we can make a script that automates tasks we find useful in the scope of computer security.

First off, you guys may want to check out http://www.autohotkey.com/docs/ for a full explanation of this scripting language. They have lots of tuts and some nice code examples to get you started. Below I will throw out some of the lines from my automation script, and explain them the best I can.

The first feature we will cover is hotstrings. Hotstrings are used to expand abbreviations as you enter them. So the first line in my script takes an abbreviation you type, in this case “[em”, which when entered will display my actual e-mail address, the example:

::[em::[email protected]

This is a very basic concept that we will expand on. Using the hotstring feature we can greatly reduce the time it takes to respond to forum posts and emails, as the following works wonders:

::[osri::
(
The customers windows install has proven to be corrupted or infected by a virus or malware, after discussing the options to the customer they agreed
to perform a reinstall of windows. The OSRI was performed and the system drivers and software has also been reinstalled. Customer is satisfied with
the results and the case is now closed.
)

After a few days of creating these hotstrings, I greatly decreased the time it takes for me to enter case information into our documentation system. Even when doing some c++ developing inside windows this can be used to eliminate typos and decrease the time it takes to develop on any project an example of this would be:

::[while::
(
while ()
{

}

)
Obviously this can be expanded to handle specific code blocks that you use often. Hotstrings are only limited in function by your imagination.

HotKeys
Hotkeys can be used to easily trigger an action (such as launching a program or sending text to the cursor). In the following example, the hotkey Alt+s is configured to open soldierx.com in your default web browser. The exclamation sign [!] stands for the alt key, for a full list of modifier symbols check out http://www.autohotkey.com/docs/Hotkeys.htm

!s::
Run http://www.soldierx.com
return

In the final line above, "return" serves to finish the hotkey. In the next example we will assign a hotkey to send keystrokes to the active window by using the send command:

!t::
Send Thanks for your time,{enter}(tab)Forsaken
return

Another hotkey I use often opens up the control panel by pressing both control keys.
^RCtrl::run Control Panel

#This below needs work I recently lost about half of my AHK scripts when I misplaced a flash drive. I am hoping to find it very soon.
Now that you guys have a general idea of how the hotkey system works I am going to give some bigger examples and just explain what it is they do and why I use them.
# fix first in next version

I f I had a dollar (US only please) for each time I heard "I wish had such and such had spellcheck" I would not still be attending school in hopes of finding a good job in the current US economy. A guy named Jim Biancolo has resolved this issue for me. Well kind of anyway. He took the list of the most common misspellings from Wikipedia and started this script, which will auto-correct misspellings in ANY application. He later added the words that MS word autocorrects and a few of his own repetitive typos. The project was later taken under the wing of the AHK community and is now very useful and includes around 5000 words. You should check it out, as there is also a compiled version which does not require AHK to run.

Well that’s it for this update, again I am showing some commonly used features of AHK but I really want everyone to understand that this is by no means a complete paper on what AHK is capable of. If you have any interest in automating windows you should check out the official AHK website. With this update I am going to add a list of features I would like to add/learn/explain in the future. Please feel free to comment or expand on any of them.

#Ideas for future article releases
1. A script to list all my games, so i can select one from the list to play it. Same goes for movies/music/TV shows
2. An emergency button combination. This would be used to say lock the computer and send an email to a friend letting them know I am in some kind of trouble and need assistance. Would be cool to make it start up a webcam so someone could login to a website and monitor my room/security system.
3. A small encryption script that will take a txt file or an input box and encrypt it using an industry standard. Would also be useful if It could decrypt the same text using a pass phrase oh how I would love to encrypt one liners and send it to friends, at which point they can decrypt.

Again this is only a functional example, scripting will become truly powerful after you personalize it to your specific needs. But creating hotkeys and hotstrings doesn't cover half of what AHK is capable of doing. It has support for creating GUI to gather or display information to the user. When you combine all of these functions you will realize that this language has a lot to offer in the terms of automation. This paper will be updated to show some examples of the more advanced functions of AHK. Now this is where I offer an open invitation to the SX community, what hotkeys or hotstrings would you use on a regular basis? The point here is developing a script to automate the most common tasks performed by the SX crew. So please send me your thoughts to [email protected] if you find this short paper useful, or if you have any questions or want to request a function for the SX AHK script. There is also a thread on the forum discussing AHK and its use.

Until next time stay safe.