- dotTech - http://dottech.org -

Enhance your computer experience with AutoHotkey

Posted By Locutus On June 8, 2011 @ 10:20 AM In Freeware Reviews,Tips 'n Tricks | 15 Comments

[1]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 [2].

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

[3]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 [4]:

+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 [5], 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 [6], 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 [7], 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:

[8]

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:

[9]

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

[10]

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

[11]

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 [12] 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 [13].
  • 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 [14] programs [15] have [16] been [17] crafted [18] 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 [19].

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 [20]*

*This has been a malware detection problem with AutoHotkey since the day it was created. As far as we know, AutoHotkey is a [21] safe [22] program [23]. 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 [24] [direct download [25]]


Article printed from dotTech: http://dottech.org

URL to article: http://dottech.org/21424/enhance-your-computer-experience-with-autohotkey/

URLs in this post:

[1] Image: http://dottech.org/wp-content/uploads/2011/01/pausesmilie.png

[2] WinSorter: http://dottech.org/freeware-reviews/21192

[3] Image: http://dottech.org/wp-content/uploads/2011/01/My-Sample-Script.ahk-Notepad1.png

[4] 1: #samedocument

[5] codec issue: http://dottech.org/tipsntricks/20911

[6] Autohotkey forums: http://www.autohotkey.com/forum/topic31698.html

[7] Lifehacker: http://lifehacker.com/5613776/enable-ctrl%252Bv-paste-in-the-windows-command-prompt-with-autohotkey

[8] Image: http://dottech.org/wp-content/uploads/2011/01/CUsersLocutusAppDataRoamingMicrosoftWindowsStart-MenuProgramsStartup1.png

[9] Image: http://dottech.org../wp-content/uploads/2011/01/CUsersLocutusMy-DropboxScripts.png

[10] Image: http://dottech.org/wp-content/uploads/2011/01/compilescript1.png

[11] Image: http://dottech.org/wp-content/uploads/2011/01/CUsersLocutusMy-DropboxScripts-21.png

[12] Jotti: http://dottech.org/freeware-reviews/21190

[13] Run command: http://www.autohotkey.com/docs/commands/Run.htm

[14] entire: http://www.autohotkey.com/forum/viewtopic.php?t=32075

[15] programs: http://www.autohotkey.com/forum/topic6422.html

[16] have: https://github.com/adampash/texter/blob/master/Releases/0.6/texter.ahk

[17] been: http://www.autohotkey.com/wiki/index.php?title=Script_Listing

[18] crafted: http://www.autohotkey.com/forum/topic16786.html

[19] AutoHotkey tutorials: http://www.autohotkey.com/docs/Tutorial.htm

[20] 2/43 detections – VirusTotal results: http://www.virustotal.com/file-scan/report.html?id=47967085c6d42d911c5c832378690027c1891a977a2fc8574fbd819e00df7de4-1295164594

[21] is a: http://www.google.com/search?q=autohotkey+virus

[22] safe: http://www.autohotkey.com/wiki/index.php?title=FAQ#Virus.3F

[23] program: http://www.autohotkey.com/forum/topic31975.html

[24] AutoHotkey homepage: http://www.autohotkey.com/

[25] direct download: http://www.autohotkey.net/~Lexikos/AutoHotkey_L/AutoHotkey_L_Install.exe

© 2008-2012 dotTech.org | All content is the property of its rightful owner.