Shortcuts allow us to be much more productive on our computers. After pressing a key combination, we have immediate access to functions that we would otherwise have to search for in toolbars, menus, and submenus. However, not all applications come with hotkeys, and even if they do, they may not do what you want.
In this tutorial, we’re using AutoHotKey to write a simple script that enables various shortcuts based on the name of the active window. This way, you can easily create keyboard shortcuts for almost any application.
In this article, Niketrainers.com.co will tell you:
Create a basic script
If you haven’t installed AutoHotKey, download the installer and install it on your Windows PC.
Open your favorite file manager and create a folder to store autohotkey scripts. While in the folder, right-click and select “New -> AutoHotKey Script”, then name your script.
Right-click the script and select “Edit”.
Your AHK script will already be pre-populated with some recommended inputs. Leave them as they are. Press Enter two or three times to insert a space between them and the script.
Enter the following if statement which will create our basic rule.
#if WinActive ( "TYPE FILENAME" ) #if
The second “#if” marks the end of our if statement. “TYPE FILENAME” is the placeholder for the values we’ll see next.
Get the Windows System ID with Window Spy
Let’s see how to add a custom feature to our script that will only be active on the Make Tech Easy website.
1. Add the following to your script:
2. Save your changes and run the script by double-clicking it. A small message box will appear. This is how the basic dialog boxes in AHK are created.
However, we use it because we need an active AHK script to access the Window Spy AutoHotKey program easily. So leave that message box active for now and pay attention to the AHK icon in the Windows tray.
3. Right-click on the little green AHK icon and select Window Spy from the menu.
4. Launch your favorite browser and visit the Make Technology Easy website. Note that the top of the information in Window Spy will show details about the active window. To name a specific application, you need “ahk_class”, “ahk_exe” or “ahk_pid”. Let’s move on to “ahk_exe” for our script. When we use Firefox, Window Spy reports “ahk_exe firefox.exe”.
5. Copy the ahk_exe file and the name of the executable at the same time, then go back to the script. Change it to:
#if WinActive ( "NAME" ) And WinActive ( "TYPE FILENAME" )
Replace “NAME” with the title of the active page; in our case we use “make” from Make Tech Easier. Replace “TYPE FILENAME” with what you copied before Window Spy, in our case “ahk_exe firefox.exe”.
Add shortcuts
Addm::
before “Msgbox, Done?” Your script should look like this:
#if WinActive ( "make" ) And WinActive ( "ahk_exe firefox.exe" ) m :: Msgbox , Done? return #if
Nothing will happen if you run the script again and pressmetroon your keyboard. However, visit the Make it easier to use Firefox page, pressmetroit again and a familiar message box will appear. You just created a shortcut to a specific window!
Let’s turn the message box into something useful. Replace everything between “ifs” with string:
^ b :: Send , I just copied % Clipboard% return
Run the script again. Then try to leave a comment under the Make Tech Easy post. If you presskontrola+bIn the answer field you will see “I just copied X”, where “X” will be the last thing copied to the clipboard. You just reassignedkontrola+bto send the string “Just copied” followed by the contents of the clipboard. You can change it to whatever you want.
AutoHotKey uses the following symbols to create shortcuts with their counterparts:
- #for Windows
- ^for inspection
- !for Alt
- +for Shift
You can also use these symbols with the Send command, which sends a text string to the active window. You can use this to reassign existing shortcuts to different keys. For example, to reassignWindows+bTo make it work like “Ctrl + C”, you could change your script to:
It is also possible to define several shortcuts. However, you cannot add two functions to the same key combination, unless they are in separate if statements that apply to different windows.
To create shortcuts for various applications and windows:
- Copy the script and rename it as appropriate.
- Replace “NAME” and “FILENAME TYPE” with others that match another application or window.
- Enter shortcuts, text expansion rules, and functions just like we saw in the first script.
Now that you know how to create application shortcuts with AutoHotKey, learn how you can use AutoHotKey to automate almost everything in Windows.