Table of Contents[Hide][Show]
Is there a way to perform repetitive tasks in just a few clicks?
Many users already know some basic shortcut keys for productivity. Instead of using your mouse to navigate around a GUI, you can just use Ctrl+S to save your work. Instead of manually minimizing every open window, you can just type Win+D to show your Desktop. But is there a way to create your own shortcut keys?
AutoHotkey is a program that you can easily learn to create custom commands with a few lines of code. Imagine being able to open your favorite websites or programs with a few keystrokes, or automatically entering the current date when you type “currdate”.
This article will go over some of the basic features you can find in AutoHotkey as well as explore some common use cases for the program.
What is AutoHotKey?
AutoHotkey is a free and open-source custom scripting language available in Microsoft Windows. It was initially developed to create keyboard shortcuts easily and hotkeys to easily automate computer tasks.
With this program, users can easily create scripts and macros that can replicate a string of keyboard and mouse input. Advanced use cases of AutoHotkey even use user interfaces and menu bars to specify what exactly you want your script to do.
Since AutoHotkey runs on C++, every script can easily be converted into a .EXE file that anyone can run even if they do not have AutoHotkey installed.
Users can install AutoHotkey in their official website. Their documentation is also beginner-friendly and extensive.
Key Features
- Ability to assign and retrieve variables
- Remap or disable certain keyboard keys
- Simulate keyboard, mouse, and joystick input
- Users can assign “hotstrings” that can replace certain text
- Custom data entry forms through GUI
- Compatibility with the Windows API
- Create custom arrays or objects.
- Comes with a wide library of functions that can help users manipulate text, compute values, and more
Basic Concepts
Here’s a preview of some of the basic concepts that you can use when building your AutoHotkey scripts.
Creating a new file
Once AutoHotkey has been installed, Windows users can quickly add a new script by selecting the AutoHotkey Script option under New when you right-click on your Desktop.
To start modifying your script, you can open the new file in your favorite text editor. Each new script includes a default script that ensures the best performance and compatibility.
Hotkeys and Hotstrings
Hotkeys or shortcut keys are combinations of keyboard keys that trigger a specific action.
In the example below, we’ve used the string “#n” to indicate that we want to use the hotkey Win + N. The next line specifies a Run command for the Notepad application. We use the return key to signal the end of the action.
The pound sign stands for Win. The “!” symbol is used for the Alt key, the “^” symbol is used for Ctrl, and the “+” key is used for the Shift key. Collectively, these keys are known as modifier keys.
AutoHotkey also supports context-sensitive hotkeys. For example, you might want to only trigger an action if you are in your favorite editor. In order to do this, AutoHotkey has a #IfWinActive keyword.
In the example below, we’ve added a #IfWinActive directive that checks first if the user is currently on the Notepad application before performing the action.
Hotstrings are mainly used to expand abbreviations as you type them. For example, you can set up an AHK script that types out “by the way” after you type “btw”.
Defining hotstring is quite easy. Simply enclose the trigger abbreviation between two pairs of colons. The hotstring activates once you type an ending character after the abbreviation.
Ending characters include parentheses, brackets,braces, punctuation marks, tabs, spaces, and the Enter key. For example, using the above script, I can type “ttylm” without the hotstring triggering.
Users can put as many hotstrings and hotkeys in a single file.
Send Key Input
In the previous examples, we’ve shown examples of actions that return text input. While this is useful in many cases, there are some instances where we might have to use the Send Key Input instead.
This feature allows you to specify in the script when a key is pressed and unpressed and how long it should remain pressed. Actions that require a key delay will usually use a Send command.
In the example above, we have a script that holds down the up-arrow key for one second. Notice that we have separate commands for pressing and releasing a key.
Run Websites and Programs
We can use the Run command to open files and URLs. Specifying a recipient with a phrase like “mailto:[email protected]” will open your default email application with the given recipient filled in.
Besides files, AHK allows you to open special Windows folders in your operating system. For example, to open the Recycle Bin, we can use that folder’s globally unique identifier or CLSID. You can browse this list of CLSIDs available on Windows.
Objects and Variables
More advanced features for AutoHotkey include the ability to use variables and objects.
Variables can be used to store text, numbers, and data from other functions. You can assign any value to a variable.
Objects are a way of organizing data more efficiently. Objects are essentially a collection of variables. In AHK, the variable names are known as keys, while the contents are called values.
Objects can be in an array format, where each value has an associated index as its key. Alternatively, we can use an associative array where the keys are strings or non-sequential numbers.
Example Use Cases
1. Keyboard Remapping
Users who want to use alternate keyboard mappings, such as Dvorak, can use an AutoHotkey script to easily set up the proper keyboard mappings.
2. Hotkeys for any Website and Program
AutoHotkey can open any program on your computer and bring up any website URL. For example, you can set up a script that opens up a Google Search when you press Ctrl + Shift + C. Your most-used programs can be a single keystroke away.
3. Fill in frequently-used file names or phrases
AutoHotkey can help you easily fill out various phrases and text strings that may be tedious to type out yourself. For example, you can create a short hotstring that types out your mailing address.
4. Custom Shortcuts for Special Characters and Punctuation
Have you ever had difficulty typing out a special character such as ñ or é? Writers may find it tedious to remember how to type an en dash (–) or an em dash (—). AutoHotkey can help users create custom shortcuts to their most-used special characters.
Conclusion
AutoHotkey is an extremely powerful program for Windows users.
The program is perfect for automating repetitive and tedious tasks. Power users and scripting fans will certainly benefit from the vast number of tasks that AHK can do with its scripting language.
Leave a Reply