xbindkeys: how to bind keys to commands (X window)

xbindkeys is a X tool to grab keys and associate them to commands.

Install xbindkeys

In Debian:
$ sudo aptitude install tk xbindkeys

Create a configuration file

We are going to create a .xbindkeysrc configuration file.

To create a default configuration file to start with:
$ xbindkeys --defaults > ~/.xbindkeysrc

We can now add key bindings to that file.

If we want to know the symbol associated to a key:
$ xbindkeys -k
Press combination of keys or/and click under the window.

m:0x40 + c:33
Mod4 + p

We can use that key combination to edit .xbindkeysrc file:

E.g: I add these lines to .xbindkeysrc file
"xrandr --auto"
  Mod4 + p

To show current associated key bindings:

$ xbindkeys -s
Control+Shift + q
"xrandr --auto &"
Mod4 + p
"xrandr --output eDP-1 --off &"
Mod4 + o

Launch xbindkeys

By default it runs as a daemon
$ xbindkeys

It is a good idea to add a line to .xinitrc file:
xbindkeys &

xrdb ~/.Xresources
xscreensaver -no-splash &
xterm &
ratpoison &
xbindkeys &

Reload configuration file

xbindkeys reload its configuration file each time it has changed. But if you want to
force it reloading its configuration file, you can send a HUP signal:

$ killall -HUP xbindkeys

When HUP signal is send to xbindkeys, changes in $HOME/.xbindkeysrc take effect only after moving mouse.


$ man xbindkeys

$ xbindkeys --help