5 / 5 ( 1 vote )

Are you like me, who want to listen to music while you work? But then your boss comes over and you quickly have to pause it? Or maybe you just want some key bindings on your linux workstation to make life a lot easier, then look no further! xbindkeys is the solution, and I will show you how in this post! it’s really easy to configure and extremely helpful.

In my example, I will use it to pause/unpause my music when i press CTRL+space no matter what desktop I’m on and even if I’m not in the terminal where MOC (the music player I use) is running.

What you need

xbindkeys is the name of the only package you need for this. It should be in the official repository for your distro. Install examples below:

Debian

apt-get install xbindkeys

Arch Linux

pacman -S xbindkeys

CentOS

yum install xbindkeys

Configuration xbindkeys

First create a file in your home directory called “.xbindkeysrc” with the following command:

touch ~/.xbindkeysrc

Then run the command as shows below. In the little window that pops up, press the key you want to see the name for. The window will then close and the terminal will print out what to write in your config to use that key.

xbindkeys -k

It will look something like this



When I press spacebar, the windows closes and the the terminal prints out what I pressed:



As you can see, it says in the last line that i pressed “Mod2” and “space”

Mod2 = my num lock

We ignore the numlock, it will show every time if numlock is enabled (might be an other key on your keyboard).

As I want to be able to press CTRL+space I want to know what multiple keys are named. You can run the same command again and press CTRL to see what it’s named, or you can run the program with “-mk” (multiple keys):

xbindkeys -mk

This way you can press multiple keys and view the output in the terminal. To quit press the “q” key or close the window with your mouse.

So, what I found out was that my CTRL key is named “Control” and Spacebar is named “space”

Edit your ~/.xbindkeysrc file using your favorite text editor and add the following lines (replace with the command you want it to run when you press the key combination):

" " Control + space

now restart xbindkeys:

killall xbindkeys; xbindkeys