“There is no real difference between work and play – it's all living.”

-Richard Branson

Custom Key Bindings in Linux

There are various ways to create custom key bindings/mappings in Linux, I’ll be using xbindkeys and Ubuntu in this tutorial. xbindkeys is a program that allows you to launch shell commands with your keyboard or mouse under the X Window System. It links commands to keys or mouse buttons, using a configuration file.

I have a ThinkPad and my keyboard has one of those blue buttons. Might as well put it to good use. I take a lot of screenshots, I’ll use it for that.

  1. Install xbindkeys: apt-get install xbindkeys

  2. Create a configuration file for xbindkeys: touch $HOME/.xbindkeysrc

  3. Identify the key to be used for launching the command:
    xbindkeys --key followed by pressing the (blue) button

Example output of `xbindkeys –key` after a keypress
1
2
3
4
5
6
Press combination of keys or/and click under the window.
   You can use one of the two lines after "NoCommand"
   in $HOME/.xbindkeysrc to bind a key.
   "NoCommand"
       m:0x10 + c:156
       Mod2 + XF86Launch1

4.   Add key binding to the configuration file $HOME/.xbindkeysrc:

This basic keybinding takes a screenshot with the blue button
1
2
"gnome-screenshot"
     m:0x10 + c:156

or

Another example that uses the blue button for a screenshot
1
2
"gnome-screenshot --window --remove-border --effect=shadow"
     Mod2 + XF86Launch1

5.   Autostart xbindkeys (without arguments) on login. You can use the “Startup Applications” tool.