So you love your Linux machine, but you must have that one (or probably a few) Windows program working on your machine. You found what felt like a magic wand, and installed Wine. But when you go to use that favorite app, the shortcut keys you’re used to in the Windows world just don’t work here in Linux! So what do you do? We’ll show you how you can map and bind shortcut keys to your Wine program. We assume you already have Wine installed.
Note that some apps require you to explicitly enable hotkeys. This is normally found in the “Options” or “Settings” menu. For example for Balabolka, you’d have to go and enable hotkeys in the settings.
The most common tools to do this key mapping are xdotool and xte. These are both key emulators that you can use to hook up scripts corresponding to key presses. Then you’ll have to use Xbindkeys to bind any special keys or buttons. Let’s see how to use these, and other ways you can map shortcut keys to Wine programs.
Xdotool lets you do many Windows tasks from the command line. It essentially lets you simulate keyboard and mouse activity. You can look up the complete mapping here, but for our purposes, we’re going to use just two basic commands –
key. First steps first – install xdotool with the usual command:
Next you create the mapping you want in this manner:
Let’s take Spotify as an example, and look at how we can map the Global Media Hotkeys. For convenience, let’s put it into a script (courtesy Arch linux Wiki) music.sh
Remember to make your script executable with a simple “
chmod“. Once you’ve mapped this, you’ll need to bind this script to any tool that actually catches key presses. Here’s how to do it with xbindkeys
The most common problem most folks run into while using xdotool or other key mapping is related to some extra Ctrl, Shift or Alt key being pressed down while they’re setting the shortcut, or sometimes having an extra key_up or key_down. There’s a simple way to remove the extra modifiers – just use the “clearmodifiers” option.
The clearmodifiers searches for any special keys like Shift, Ctrl, or Alt that are being pressed, removes them by sending the appropriate key up sequence, runs your xdotool command, and restores your modifier by sending the appropriate key down. You can look up further details on the man page.
An example with Foobar
We just saw how to map the global media hotkeys with Spotify. It’s much simpler with foobar. Wine normally allows foobar to map the multimedia keys, if not already mapped by some other program. To set up global multimedia hotkeys with Foobar + Wine, here’s what you can do:
– Open the “Gnome Configuration Editor”.
– On the left navigation pane, select “/apps/metacity/keybinding_commands” and set up
Then go to “/apps/metacity/global_keybindings” and define:
Xte is another tool you can use to map keyboard inputs. It’s part of the xautomation package and you can install it with
It generates fake inputs (key or mouse) using the XTest Extension. Let’s take a simple example. Say you want to map “Ctrl + PageUp” to switch to the previous tab and make use of the XF86Back key. Create a script with executable permissions (755), call is sc_back:
Then make sure you map XF86Back as the shortcut for sc_back. This should let you switch to the previous tab with “Ctrl + PageUp”.
Depending on exactly what you want to achieve, there are many ways to map and bind shortcut keys. We’ve covered some of the examples in this tutorial, but there are many other ways as well. For example, Autokey provides one of the cleanest ways. Like the xdotool method we described above for Spotify, it lets you create scripts and map them to certain shortcut keys. Our earlier tutorial on this topic can show you how to use it. You can experiment to figure out which method works best for you.
Our latest tutorials delivered straight to your inbox