Enhance your computer experience with AutoHotkey

Are you finding yourself using the mouse more often than your keyboard? Does your keyboard feel a little bit neglected? Using AutoHotkey you can better integrate the keyboard into your regular routine, infinitely enhancing your computer experience.

Image credit: Locutus

What is AutoHotkey?

AutoHotkey is an extremely powerful scripting language. While its main purpose is to enhance the use of one’s keyboard (it allows users to do almost anything with the keyboard), many standalone programs have been built using AutoHotkey, such as the recently mentioned WinSorter.

AutoHotkey scripts revolve around the idea of remapping keys. To takes keyboard keys and maps them so they perform a function other than what they normally would. The general format of the code is relatively easy to follow:

hotkey::remapped key

However, as already mentioned, simple remapping of keys just scratches the surface of what AutoHotkey can do.

AutoHotkey Example 1: Get rid of the annoying Caps Lock key

One simple, but brilliant, example of what AutoHotkey can do is remapping the Caps Lock key to the Shift key (I love th is feature). For this, you can simply make a blank document containing this single line:

CapsLock::Shift

After saving the document with the file extension .AHK and double clicking on it, your Caps Lock button will become a third Shift key.

If you want to keep the Caps Lock key, say for use in a shouting match, you can make the script so Shift+Caps Lock initates Caps Lock. Do to this, add a new line in the same document1:

+CapsLock::CapsLock

Now with the script activated, the Caps Lock key will act like a Shift key and pressing Shift + Caps Lock will initiate Caps Lock. (Pressing Shift + Caps Lock again deactivates Caps Lock, just like how normally pressing the Caps Lock key deactivates it when it is on.)

1: You can stack infinite lines of code or other scripts within one script/document. It’s super convenient!

Example 2: Remap the Windows Media Player pause button

Windows Media Player 12, the one bundled with Windows 7, is a great media player. However, aside from the codec issue, it has a major shortfall: When using Windows Media Player, you have to press either the giant blue play/pause button or Ctrl+P to pause whatever you are playing. With an AutoHotkey script you can pause media in Windows Media Player just my pressing the spacebar on your keyboard.

To pause media in Windows Media Player with your spacebar, either create a new .AHK script – like discussed previously – and add the following coding (you may also add the following code to an existing .AHK script):

GroupAdd,mplayer,Windows Media Player ;Adds Windows Media Player to the group mplayer
GroupAdd,mplayer,WMPTransition        ;Adds WMPTransition to the group mplayer
#IfWinActive,ahk_group mplayer        ;Makes commands only work in mplayer
Space::Send,{Media_Play_Pause}        ;Makes space bar send Play/Pause media button
#IfWinActive,                         ;Makes commands work in all windows again

As you can see, there are lots of semicolons in the code. As far as the script is concerned, text after semicolons is ignored. Text after semi-colons are just comments for someone reading the script to try to understand what is going on. You can delete text after semi-colons if you want, with no repercussions – the script will still function fully.

This script is from the Autohotkey forums, the best place to discuss all things AHK.

Example 3: Make Ctrl+V paste in Command Prompt

Want to use your keyboard to paste into Command Prompt? Good luck with that… because Bill Gates refuses to allow you to do this! Instead, to paste in Command Prompt one must right-click with the mouse and click on Paste. A simple AutoHotkey script can allow you to use Ctrl + V to paste into Command Prompt:

#IfWinActive ahk_class ConsoleWindowClass ;Checks for Command Prompt
^V::                                      ;If Ctrl+V is pressed...
SendInput {Raw}%clipboard%                ;Send the raw clipboard data
return
#IfWinActive                              ;Allows for other scripts

This script checks for Command Prompt and then “types in” the clipboard data whenever Ctrl + V is pressed.

Like the previously discussed scripts, the above script can either be entered into a whole new .AHK script, or it can be appended to an already existing script.

This example script is from Lifehacker, my favorite place to find new AHK scripts.

Making scripts run at booting time

Many AutoHotkey scripts are ones that users want to run all the time. So it makes sense to make them automatically start at Windows boot. To make a script run at Windows boot, simply create a shortcut to the respective AHK file and place it in the Startup folder. In other words,

  • Go to your .AKH file, right-click on it, and click on Create Shortcut.
  • Cut/copy the shortcut you just created.
  • Access the Startup folder by navigating to C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup if you are on Windows Vista/Win7 or C:\Documents and Settings\%username%\Start Menu\Programs\Startup if you are on Windows XP.
  • Paste the shortcut in the Startup folder:

Making scripts standalone

By default AutoHotkey needs to be installed to run a .AHK script. So what if you want to use the script on a computer where AutoHotkey is not installed (or want to share the script with someone that doesn’t have AutoHotkey installed)? To allow for AutoHotkey script usage anywhere, AutoHotkey allows users to compile scripts into standalone executables. These standalone executables can be used on computers where AutoHotkey is not installed.

To compile a script into a standalone executable, first open Windows Explorer and navigate to your script:

Then, right click on your script and hit Compile Script:

You’ll (almost) instantly get a second copy of the script, but this time it will be an executable file:

Take this executable wherever you want to use it. You can even share it with other people online.

There is one thing to note about compiled scripts (aka standalone executables), however. Due to some bad programming on someone’s part, some antiviruses detect AHK’s compiled scripts as viruses. While many of these detections are false-positives, there are bound to be malicious AHK-compiled executables out there. As always, exercise caution around executables, even if you made them. If you are suspicious about a file, running it through VirusTotal or Jotti will generally give you an idea as to if it is malicious or not.

Writing your own scripts

Copying someone else’s scripts is a quick and easy way to get things done. However, not only is copying not fun but someone may not have created a script that you need; so you may need to create your own script. Luckily, AutoHotkey is, as far as pseudo-programming languages go, fairly easy to code for. Here is a list of things you can do in AutoHotkey:

  • Remap & remake keyboard shortcuts with any and all keyboard buttons.
  • Send commands only to certain windows, like the previously mentioned Command Prompt one.
  • Make certain shortcuts open programs or websites with the Run command.
  • Add user interfaces to commands.
  • …Anything you can think of.

The capabilities of AutoHotkey are nearly endless. As already mentioned, not only is AutoHotkey used to tweak how users interact with their computers, entire programs have been crafted in AutoHotkey.

If you are looking to write your own AutoHotkey scripts – or even whole programs – the best place to start learning are the AutoHotkey tutorials.

Conclusion

AutoHotkey is an amazingly powerful program/scripting language and is a force to be reckoned with.  With AHK scripts, you have the power to do anything and everything with your keyboard… and then some. Sound too good to be true? Try it yourself, and find out!

Version reviewed: v1.0.90.0 of AutoHotkey_L

Download size: 2.50MB

Supported OS: All Windows

Malware scan: 2/43 detections – VirusTotal results*

*This has been a malware detection problem with AutoHotkey since the day it was created. As far as we know, AutoHotkey is a safe program. However, by proceeding to download AutoHotkey you recognize and accept any risk associated with the program. Me, Ashraf, dotTech, and anyone else are not responsible for any gain or loss incurred by use of AutoHotkey.

AutoHotkey homepage [direct download]

Related Posts