Assign an AHK Global Hotkey to Send Text or Copy It to Your Clipboard

This could be very handy if you find yourself wanting to send a specific phrase to an application from time to time.
In the past I’ve written about using AutoHotKey (AHK) to launch programs with global hotkeys and remap keys. This time around we’ll focus on inserting text into any app through a hotkey.
You may want to consider doing this if you have a phrase like an address, URL, or a response to a specific question if you happen to do customer support. It’s also useful for tricky to type words or names that might be using accent characters that your keyboard doesn’t easily support typing.
# Use Case
What led me to setting this up is if I want to write Türkiye, my options are
to copy it from another location such as a Google search or use ALT codes.
Weirdly enough using ALT + 0252 will happily output ü but ALT + 0287 will
not output ğ on my machine so your mileage may vary depending on the character
you want to use. In any case, neither options are ideal.
Life can be way easier with a global hotkey so when I press Win + u it
outputs that word to the current app in focus.
I picked u because I’m already using t and y. It was only a temporary
bind leading up to my trip to Türkiye and writing my Docker Captain’s
summit
post. I got tired of having to copy / paste it since I referenced the word so
many times!
It would also be super easy to change it to be copied to your clipboard. We’ll go over both examples in case you have a use case where you want it copied instead of sent. I personally went for the sent approach so my clipboard stays unmodified, it also avoids needing to press (2) key combos (one to copy it and one to paste it).
There are other types of programs that do similar things around text expanding or replacements. The idea there is you can type an abbreviation of your choosing and have it “expand” to a longer phrase. That could be useful but in my case I only have 1 more thing that I wanted assigned to a hotkey and I’m already using AHK for other global hotkeys.
What About on Mobile?
This is way off topic from AutoHotKey but on Android devices (and I’m sure iOS), you can add custom words to your active dictionary with an optional shortcut. For example if I type “turkey” in any app then it proposes Türkiye to select but I can still enter “turkey” if I want.
# Setting Up the Hotkey
I’m going to expect you already know how to create and run the AHK script. If you don’t, that’s ok. Skim my other post on AHK for the basics. You’ll be up to speed in a few minutes.
#u::Send Türkiye
The above binds Win + u to send Türkiye to the current app in focus. Send
only sends the string or keys you tell it, it will not send it by pressing
enter. That’s perfect because all it will do is insert that string at your
cursor, it’s up to you to figure out what to do next.
In a lot of programming languages it’s normal to wrap strings in quotes but in this case we don’t need to do that. If we did add quotes they would be literally output.
If you want to copy it to your clipboard instead you can do #u::Clipboard = Tükkiye. Keep in mind that will only copy it to your clipboard. It’ll be on you
to paste it.
A Special Note on Special Characters
When you save your AHK script with Notepad (the default “Edit this Script” app) it will be saved with an encoding of UTF-8 by default. If you try to send keys that contain “special” (accented, etc.) characters then it will very likely come out garbled – at least it did for me.
The solution is to save your AHK script using an encoding type of “UTF-8 with BOM”. That should be an option that’s available (it was with Notepad). Once you do that and reload your script you should be good to go without further changes.
The video below shows how it works.
# Demo Video
Timestamps
- 0:18 – Use case
- 0:55 – Sending keys
- 1:20 – Copying to the clipboard instead
What type of phrases will you assign to a hotkey? Let us know below!