March 28, 2012

Techbits #12: AutoHotKey - Create and not just configure hotkeys!

You might have heard about hotkeys or used some application to configure/setup hotkeys for invoking your favourite applications.

AutoHotKey helps you achieve not just that but also much much more including automating almost anything by sending keystrokes and mouse clicks. Anytime you find yourselves repeating something again and again, it should trigger you to automate it and it is exactly where AutoHotKey comes handy. It appears a little bit daunting at first but I strongly urge you to overcome that initial inertia and start using the tool - it increases your productivity greatly and you'll really appreciate it.

Go to http://www.autohotkey.com/ and try the installer!

Provided below are few examples to get you quickly started. These code snippets have to be kept in the configuration (.ahk) file of AutoHotKey. Note that the lines starting with semicolon are comments.

Let's start with the simplest hotkey configurations.

Hotkey #1

; when you press Win+n (Windows key + n), run an application called "Notepad"
#n::Run Notepad

Hotkey #2

; when you press Win+m (Windows key + m), run an application called "Notepad++"
#m::Run Notepad++

Now, let's move on to a little bit more complex ones.

Hotkey #3

#g::
Run
http://www.google.com/search?q=%clipboard%
return

What does that do? When you press Win+g (Windows key + g), it constructs a URL with the clipboard contents and opens it - in this case, it googles for what's there in your clipboard.

Hotkey #4

#h::
Run
http://www.hindu.com/%A_YYYY%/%A_MM%/%A_DD%/10hdline.htm
return

When you press Win+h (Windows key + h), a URL is constructed using current year, month & date and opened using your default browser - hope it's Firefox by now ;)

Even more complex ones - note that this complexity representation is just on a relative scale and there are much more complex ones!

Hotkey #5

#p::
Run D:\Projects\Customer
WinWait
D:\Projects\Customer
WinActivate
Send ! x
Send !veo
return

When you press Win+p (Windows key + p), opens the specified folder in Windows Explorer, maximizes it (Alt + space + x) and opens the folder view (Alt+v+e+o).

Hotkey#6

#a::
InputBox, varInput, Please enter some random text...
Run, notepad.exe
WinWaitActive, Untitled - Notepad
SendInput, %varInput%
SendInput, !f{Up}{Enter}{Enter}
WinWaitActive, Save
SendInput, SomeRandomFile{Enter}
MsgBox, Your text`, %varInput% has been saved using notepad!

When you press Win+a (Windows key + a), well, instead of me trying to explain what's there, just go through it and you'll get an idea.

To summarize, this blog post just goes on to show how AutoHotKey acts like a Swiss Army knife and how much powerful it can be.

No comments: