Windows Scripting With AutoHotKey (AHK) v1.2

6 replies [Last post]
forsaken
Offline
Neophyte
Joined: 2009/04/28

Windows Scripting With AutoHotKey (AHK)

I am not so sure this topic would deserve and entire tutorial, but I find it very useful in my day to day activities. 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 an.

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:

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 preform a reinstall of windows. The OSRI was preformed 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 Handel 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 crusor). 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 hald of by AHK scripts when I misplaced a flash drive. I am hopeing 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 spellcheck" I would not still be attending school in hopes of finding a good job in the current US economy. Well a guy named Jim Biancolo has resolved this issue for me. Well kinda 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 repedative typos. The project was later taken under the wing of the AHK community and is now very usefull 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 thats it for this update, again I am showing some commonly used features of AHK but I really want everyone to uderstand this is by no means a complete paper on what AHK is capable of. If you have any interest in autmating windows you should check out the offical 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 combanation. 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 somone 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 encrpyt it using an industry standard. Would also be usefull 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 alot to offer in the terms of automation. This post will be updated to show some examples of the more advanced functions of AHK. Now this is were I offer an open challenge to the SX community, what hotkeys or hotstrings would you use on a regular basis? The point here is develop a script to automate the most common tasks preformed by the SX crew. So please post a response to this topic if you find this short paper useful, or if you have any questions or want to request a function for the SX AHK script.
-------------------------------------------
A quick refrence
-------------------------------------------

! Alt
^ Ctrl
+ Shift
# Winkey

Refrences
http://kikizas.net/en/usbapps.ahk.html (Awesome script which gave me some great ideas for AHK in the future. I could not find the authors name and I am not sure if this is the original posting if anyone knows the author or were the script was originaly posted please let me know so credit can be given)