Isn't it annoying when almost identical applications use different key combinations to achieve the same result? Worse yet, don't you just hate it when a piece of software insists on using obscure keyboard shortcuts without offering an option to remap them? Wouldn't it be great to have complete control over how your keyboard works in each app? Well, that's possible, thanks to AutoHotkey.
With AutoHotkey, you can remap your entire keyboard or create custom shortcuts, both "globally" and for each app individually. If you want, you can even have custom text strings, or even entire templates, for each app bound to the same key combinations. You just need AutoHotkey and a text editor, even Notepad will do. Sounds interesting? So let's go right in.
Getting started with Windows Spy on AutoHotKey
Many keyboards today come with software to create custom shortcuts and macros. However, as we will see, AutoHotkey is more versatile as it is keyboard independent.
With it, your “keyboard customizations” will not be tied to a particular keyboard. You'll be able to take your customization script to other computers and have your custom app shortcuts and shortcodes up and running in no time.
Since we're just getting the ball rolling in this article, if you want a proper introduction to AutoHotkey, check out our Quick Guide to AutoHotkey for Beginners.
Starts with downloading AutoHotkey from its official site. Then install it like any other app. You don't need to run it afterwards. It automatically springs into action when you run a script created for it. So, let's create such a script.
With AutoHotkey installed, right click anywhere on your desktop or within a folder where you want to create your script. Choose New > AutoHotkey Script. Give your script a name and press Enter.
With AutoHotkey, you can create "global" shortcuts that will be active everywhere or application-specific shortcuts that will work only within an active application window. To "target" a specific app, you need to identify it in your script. AutoHotkey can help with that through Window Spy.
Double click on your currently blank script to run it and with it AutoHotkey. Right click on the AutoHotkey icon in the Windows tray and choose window spy from the menu that appears.
To find the identifiers needed to target an application, leave Window Spy on your screen and click on your application's window. Then look at the class_ahk, ahk_exeand ahk_pid entries, at the top of the Window Spy window. In our case, we wanted to target the popular note-taking app Obsidian. Since other software might have similar ahk_class and ahk_pid, we use their executable file as our target, using ahk_exe obsidiana.exe, as mentioned in Window Spy.
When you know your goal, it's time to write the script.
Time to script AutoHotKey
Right click on your script and choose edit script to open it in your default text editor. As you will see, it will pre-populate with some values that help with compatibility and performance. Ignore them, hit Enter once or twice, and target your app using:
#IfWinActive APP_IDENTIFIER
Replace APP_IDENTIFIER with the actual target you copied from AutoHotkey's Window Spy. In our case, this translated to:
#IfWinActive ahk_exe Obsidiana.exe
When writing AutoHotkey scripts, you can use the following symbols for modifier keys on your keyboard:
- ! for all
- + for change
- ^ for CTRL
- # for Windows key
However, before you create your actual shortcuts, test whether the script will only work when your chosen app is active. The easiest way to do this is by using what AutoHotkey calls "a message box" or rather a "message box".
Type the following directly below the line where you noted your chosen app:
^a::
msgbox it works!
returnIf translated to plain English, this would look like this:
- When CTRL+A are pressed together on the keyboard...
- …display a message box on the screen saying “it works!”.
- When the user acknowledges that message box, it returns to the previous state.
Run your script, press CTRL+A on your keyboard, and nothing should happen. This is because you have selected a specific app but have not changed it yet. So, activate that app's window, hit the same combination, and you should see a message box pop up saying "it works."
Now switch back to any other app and try your key combination again. Hopefully, nothing should happen. If so, this means that your MSGBOX fires only in your specific application, which is the desired result we want from this script.
If the key combination is "leaked" into other applications, double check its syntax and make sure there are no typos in your selected target.
How to make custom keyboard profiles for your apps
AutoHotkey makes it easy to remap what the keys on your keyboard do, both individually and when combined. Would you like to swap the A and B keys? In AutoHotkey syntax, this would look like this:
a::b
b::aHowever, you probably don't want to remap individual keys, but instead have combinations of multiple keys, with one or more modifier keys, to perform specific actions.
To build on the above example, if you want B to appear when you press CTRL+A, and vice versa A to appear when you press CTRL+B, try:
^a::b
^b::aOf course, this is just an example. In real life, pressing multiple keys to type a single character is the very definition of backfire. In contrast, assigning text strings to key combinations can significantly speed up text entry. To type your name, email address, or any other text when you press a key combination, you can use AutoHotkey's “send” command. This "tells" AutoHotkey to, as its name implies, "send" the string of text that follows it to the active window. In action, it may look like this:
^+O::
send Odysseas
returnIn the above script:
- We start by “telling” AutoHotkey that it should do something when we press Shift + CTRL + O at the same time.
- That "something" is sending the string "Odysseas", which happens to be the name of this writer, to the active window.
- Finally, with "return", we say the equivalent of "that will be all, thanks AutoHotkey!".
Try experimenting with different key combinations and have AutoHotkey send various text strings to your chosen application. You can have multiple rules in the same script.
Using keyboard shortcuts to enter text strings can be useful for instantly entering your name and email address. However, it is not intuitive when typing. After a while, it becomes hard to keep track of what dozens of shortcuts are doing. That's where text expansion can help.
Instead of assigning specific key combinations to text strings, AutoHotkey allows you to define shortcodes. Then, when it detects that you typed one of them, it can automatically replace it with a longer text string. It's as simple as:
:*:MUO~::Make Use Of- The “:*:” at the beginning of the line indicates that this is a text expansion rule.
- Next comes the shortcode, which in our case is “MUO~”.
- As with shortcuts, “::” are the logical equivalent of “=” in this scenario.
- The last piece of the puzzle is the actual text string that we want to replace “MUO~” with.
With this rule, every time we write MUO ~ in our specific application, AHK will jump out and replace it with Use.
Once you've finished defining the rules for one app, you can target another in exactly the same way. Use “#IfWinActive APP_IDENTIFIER” again, this time targeting another app window, and write your rules directly below it.
Repeat as many times as you like, creating profiles of app-specific shortcuts and shortcodes.
Since AutoHotkey scripts are basically text files, here's a clever idea: incorporate other scripts into yours and make them application-specific too! Check out our list of great AutoHotkey Scripts. Pick any you like, but instead of using them as stand-alone scripts, open them in a text editor.
Copy their contents and add them to an app targeting section of your script. Save and re-run your script, and in theory those scripts should work as part of yours when the targeted application is active.
Make your keyboard smart with AutoHotKey
As you'll discover in the long run, creating such scripts is a process, not a one-time deal. As your demands and the way you use your software change, so will your scripts.
By continually expanding and tweaking your scripts, you may soon feel like hackers are depicted in the series as tech illiterate. By pressing half a dozen keys and obscure combinations of them that only you know, a wall of text can appear on your screen as if by magic.









