AutoKey: How to Replace Characters with Predefined Text Automatically in Linux

Shutterstock / Narith Thongphasuk

Welcome to AutoKey, the free desktop automation utility for Linux. Do you often use patterns, repeated strikes, or other repetitive tasks? If so, AutoKey is a great toolkit that you don’t want to miss!

What is AutoKey?

Suppose you often enter your email address or postal address. It can be a little frustrating having to type it every time. Let AutoKey do it for you! All you have to do is associate a keyboard shortcut – a set of typing events – with a particular blurb.

Another easy-to-configure feature is keyboard automation. AutoKey supports various key events such as pressing the left or right cursor (the left and right arrows on your keyboard). To include it in your blurb, you just need to use a little command that represents what to do:

Autokey keyboard shortcut sequence example

In this sequence, we insert (as text) the code HTML tag, then we press the left key seven times. This comes in handy when you are developing HTML in a text editor and want to quickly insert a code tag and be taken back to where the code started (first code tag), and before the end of the code block. code (second tag, / code). In other words, the seven presses on the left get us right inside the> <brackets.

We can also automate the filling of forms by inserting tabs etc.

Unfortunately, there are a few minor issues with the AutoKey program that you should be aware of. On Ubuntu 20.04.1 and using dpkg based install, AutoKey may crash when trying to record a macro using keyboard / mouse (Tools> Record Keyboard / Mouse). This functionality is generally not required for the purposes described in this guide.

Another problem is that AutoKey is somewhat complex to set up the first time around, unless you have a guide like this to follow. Mainly the ability to assign keyboard shortcuts (abbreviations as well as keyboard shortcuts) to folders as well as individual “phrases” (think of this term as actual keyboard assignments to blurb).

Finally, AutoKey, at least on Ubuntu 20.04.1, sometimes fails to respond to a keyboard sequence you’ve programmed it to respond to. A simple solution for this problem is to click on the AutoKey icon on the Dock to bring it to the foreground and click on it. You will find that if you return to your workspace, the keystrokes will work again.

Even with these shortcomings, which can be resolved in due course, AutoKey is an indispensable tool. Not having to type in your address over and over again, just press two to three keys to paste in your email (all keystrokes are deleted automatically), and the ability to have complete document templates for the cost of a few keystrokes and a mouse click (to confirm the keyboard sequence), are invaluable.

Installing AutoKey

This guide assumes that you already have AutoKey operational on your system. If you haven’t installed it yet, you can find step-by-step instructions on the AutoKey project page on GitHub for different operating systems:

For Ubuntu, Mint, and other users of Debian-based operating systems, see Debian and its derivatives.

For Arch, see Installation of Arch AutoKey, and for Gentoo see Installing Gentoo AutoKey

You can also install AutoKey using Python pip, see pip based installation

If you already have an existing AutoKey installation, it is important to remove it first. And, before doing so, you might want to save your configuration to ~ / .config / autokey.

Configuring AutoKey

Once you’ve configured AutoKey, open it and you should see the main interface:

AutoKey main interface

As you can see I already have an AutoKey setup. AutoKey has many features, including a full scripting interface:

Autokey script

The first thing you’ll want to do is configure preferences. Click Edit> Preferences. You will be presented with the following window:

Autokey Preferences

We check the first 3 options to (1) make sure AutoKey starts on startup, (2) automatically save changes, and (3) to show a notification icon in the taskbar, which in Ubuntu looks like this:

Autokey taskbar icon

You can use this notification icon to quickly use certain items without having to use keyboard shortcuts, as well as to open the app directly.

Using AutoKey: Keyboard Shortcuts

Ready to configure some keyboard shortcuts? Click the New icon> select Phrase> assign a name to your new phrase, such as “My address”> OK:

Autokey - creation of a sentenceThen we can enter our address:

Entering the address in Autokey and configuring the Autokey options

Enter the address first (1), then select “Always ask before you paste this sentence” (2), as you will want to get some form of mouse confirmation when you have typed your keyboard shortcut sequence. The reason is that you might be in an app, like your Slack workspace at work, and accidentally typing your keystroke associated with the address.

As this particular sequence contains new lines (for example after “My name”), when these keyboard sequences are sent, you will have no way to stop them and all the text will be sent to where you are working. As the new lines confirm (like entering) in many communication tools, your message will be sent (except the last line) even before you can say “ whoopsie ” 🙂

Then we also add it as a new option to our notification / taskbar icon by clicking on “ Show in notification icon menu ” (3) and lastly we make sure we paste by keyboard, although you might want to experiment with other options in this field for various text paste (ie insert) scenarios.

Almost finished. Now we need to assign a sequence / keyboard shortcut and for that we click on “Set” (5) for the abbreviations. We are then presented with the following dialog box:

Abbreviation and abbreviation options set by Autokey
First, click on the “Add” button (1). First, type your favorite keyboard sequence (I usually use a letter and prefix it with ‘//’ because it’s a rarely used keyboard sequence (unless you’re a programmer who types comments directly after // the remark lines instead of using a space).

In this case, we define “// m”. Now comes a slightly tricky part due to a minor flaw in AutoKey’s GUI. Do not click anywhere other than the white space just below the newly defined abbreviation. For example, click where the circle (2) is in the screenshot above. This locks the abbreviation / keyboard sequence instead of deleting it again. You will get used to it soon.

Next, we want to make sure that the “Remove typed abbreviation” box is checked (3) and that we select “Trigger immediately (does not require a trigger character) (4). Remember how we mentioned that some things confusing? This is one of them. You can define trigger characters above and beyond, as a prefix, for keyboard sequences / abbreviations, but this is often unnecessary and we can enable easier use of AutoKey by selecting this option Finally, click “OK” (5) to confirm everything.

Finished! Now just open your favorite text editor (yes, even vi / vim in a terminal will work!) And type your keyboard sequence “// m”. If all went well, you should now see a small “My Address” pop-up where your mouse cursor is at the time, allowing you to click on it and render the text:

Address output generated by Autokey

If you see output similar to the following:

Incorrect Autokey output

Try changing the “Paste Using” method on your keyboard for the phrase to “Clipboard (Ctrl + V)” instead:

Changing the Autokey Keyboard Paste Method

And you should be ready.


AutoKey is a great utility that can save you many hours of repetitive typing work.

This however comes with its own shortcomings and even the issues it talks about. AutoKey was around for many years and – with the hope that current developers will correct some of the shortcomings – will be there for many productive years to come! Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.