• ARTICLES
SEARCH

How-To Geek

How to Customize Shortcut Keys for Any Linux Application

One of the more annoying problems with Linux has always been the lack of AutoHotkey support, so you couldn’t customize your shortcut keys—but now with the open source application AutoKey, you can do that and more.

AutoKey is a desktop automation utility that lets you manage blocks of text and use abbreviations and hotkeys to save yourself time while typing—but you can also use it to remap hotkeys in applications. For instance, if your favorite application used Ctrl+Q to quit and you didn’t want it to, you could remap that key using AutoKey.

The Scenario

For our test scenario today, I’m going to remap the Ctrl+T key combination to Alt+T instead. Why, you ask? The Ctrl+T shortcut key is used in every browser to open a new tab, but since I use Google Chrome and like to open new tabs constantly to search, the Alt+T shortcut key is a lot easier for me to hit without moving my hands from the front row.

image

To accomplish this task, we’ll use the amazing AutoKey tool, which is a lot like AutoHotkey on Windows, except it’s made for Linux and is capable of using Python scripts.

Installing AutoKey

You’ll want to open up the Synaptic Package Manager and do a quick search for autokey, check the box, and then install the package. You could also install it using the apt-get command like this:

sudo apt-get install autokey

image

Remapping Shortcut Keys with AutoKey

Once you’ve got the utility installed, you can open up the configuration through the tray icon and create a New Phrase. The name on the left-hand side doesn’t mean anything, I just like to name them according to the hotkey that I’ll be assigning.

Use the Set button next to Hotkey to assign the hotkey you want to use, click the modifier key—in this case, I’m assigning Alt, and then click the Press to Set button and the key you want to use. For my example, I’m using Alt+t, and you’ll notice the character is lowercase, which is important—if you pressed Shift+T there, AutoKey would get confused.

image

Once that’s done, you can put the following into the text box:

<ctrl>+t

Click the save button, and you’re done. Now you can open up your browser and use the Alt+T combination instead of Ctrl+T, and it should open up a new tab.

How does this work? When you press the Alt+T hotkey that you’ve assigned, AutoKey sends the keystrokes to the currently active application, and since the keystrokes in this case are Ctrl+T, Google Chrome assumes that you pressed the shortcut key for a new tab, and responds accordingly.

Filtering by Window

The only problem is that the shortcut key now is activated for all windows. To fix this, we can setup a window filter using the Set button, and then type in something similar to this:

.*Google.*Chrome

image

You might be wondering what the .* is all about—this filter uses regular expressions to find the window title, so you’ll need to use .* to match any characters that aren’t specified, including the space in this case. Note: You could use a single period character to represent a space if you want.

Using Special Keys in AutoKey

When you’re creating a new phrase, you can use the following special codes to simulate pressing one of the special keys. There’s actually a much bigger list of special keys, but these are probably the most important ones you’ll need to use:

  • <ctrl>
  • <alt>
  • <escape>
  • <tab>
  • <shift>
  • <super>  = Windows Key
  • <enter>

Combining Keys

If you want to combine together a number of keys, you’ll use the + character, like this:

<ctrl>+<shift>+<tab>

If you needed to actually insert a + symbol, you’d need to use <np_add> instead.

AutoKey Rocks!

There’s any number of uses for this technique besides just remapping shortcut keys—you could automate a series of keystrokes to perform a task, for instance. The possibilities are endless—but what would you use it for?

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 08/26/10

Comments (13)

  1. Tangmeister

    How do you press ALT T without moving your hands?

  2. The Geek

    Without moving my hands from the normal typing position, of course.

    Also, I can telepathically communicate with my keyboard without requiring the use of hands. It’s a skill you get when you actually master sarcasm. Keep trying.

  3. Luke Faraone

    Wow, thanks for the coverage here and on Lifehacker! Glad to see people are using and enjoying the application.

    – the maintainer of Autokey in Debian :)

  4. CutTheRedWire

    Question: Can this program override mouse buttons too?

  5. J.Park

    Can I replace ctrl+c with ctrl+j ? I tried but I could not.
    I am a Dvorak Keyboard user, so QWERTY’s ctrl-c is ctrl-j for me.

    However Ctrl-C to Alt-C works fine (with a little bit delays though…).
    Can anyone help please?

  6. J.Park

    Sorry! It was Ctrl-C to Alt-J, which works good.

  7. lefty.crupps

    Is this a GTk app for the GNOME desktop, or will it work anywhere? KDE has great keyboard mapping possibilities to which I just keep adding new shortcuts and I love it.

  8. Luke Faraone

    @lefty.crupps There is also autokey-qt, which is designed to integrate well with the KDE desktop. -qt is available in Ubuntu 10.04 and later.

  9. pw

    Unfortunately, it depends on almost the whole of KDE.

  10. pw

    Oops – sorry – that’s the qt version; the gtk version does not.

  11. andrew

    great post! the hint for insertion of ctrl char was missing for me in other descriptions. thank you!
    i think i can use autkey to use the CyKey chording keyboard (uses one hand only!) with linux now.

  12. Nelson

    Hello guys,
    Anybody has any idea on how to import AutoHotKey abbreviations, etc?

    Thanks

  13. mickleberry

    Thanks h2G for the overview.. seems this could be what i’m looking for. I’d like to second Nelson’s question.. looking for a way to import all my autoHotkey abbreviations from windows to ubuntu. Kind regards, michael

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!