xbindkeys

Introduction

Shortcuts do not only reduce real-life ways but also our digital ones. Ubuntu features a Keyboard Shortcut Manager, which offers basic support for a given number of tasks. In contrast, a fundamental empowerment for your fingers is xbindkeys – a small program allowing to run commands independently from the Linux window manager. Sounds nice, in practice it is even nicer.

Installation

Easier than eating spaghetti:

sudo apt-get install xbindkeys

Configuration

The configuration file is located in your Home directory named .xbindkeysrc. If the file is not existing just create it. The entries are made with your favorite text editor in the form of:

# this is a comment explaining the keybinding
"the command"
   control+f #the key or combination of keys

Mind to put the code inside ””! For example, if we want to start gedit with Ctrl+Alt+f it would look like this:

#start gedit
"gedit"
   ctrl+alt+f

The easiest way of finding the code for your keypresses is to use xbindkeys options -k (for single keycodes) or rather -mk (for combination of keys). Open a terminal and run

  • xbindkeys -mk
  • press the desired combination, for example: Windows key left and q
  • it shows the output:
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.

--- Press "q" to stop. ---
"NoCommand"
    m:0x50 + c:24
    Mod2+Mod4 + q

The line Mod2+Mod4 + q is your key combination, which should be copied to your .xbindkeysrc file.

You can even use your mouse keys for creating keyboard shortcuts. The codes are:

  • b:1 – left mouse key
  • b:2 – middle mouse key
  • b:3 – right mouse key

Each modification of the configuration file has to be followed by a restart of xbindkeys. Since version 1.8.3 this shouldn’t be necessary (haven’t confirmed this myself). Anyway, the restart is done by:

  •  pkill xbindkeys
  • followed by

     xbindkeys

Autostart

In order to start xbindkeys automatically during startup:

  • System > Preferences > Startup Applications
  • click on Add
  • give it a name: Xbindkeys would be a nice idea
  • for the command type: xbindkeys

MPD

Xbindkeys is a convenient way to communicate with your music player daemon using the mpc package which passes ordinary commands to the MPD. The shortcuts are global, which means while surfing the web or writing a document your keyboard shortcuts work without bringing the corresponding application to the front. Using mpd no window needs to be open in the background. The daemon can be controlled solely using shortkeys. First, install the mpc package and then select from the commands listed in the manual of mpc (command: man mpc) or here. I personally use the Windows sign with the arrow keys for play, pause, stop and seek. Have a look!

# For the benefit of emacs users: -*- shell-script -*-
###########################
# xbindkeys configuration #
###########################
#
# Version: 1.7.1
#
# If you edit this file, do not forget to uncomment any lines
# that you change.
# The pound(#) symbol may be used anywhere for comments.
#
# To specify a key, you can use 'xbindkeys --key' or
# 'xbindkeys --multikey' and put one of the two lines in this file.
#
# The format of a command line is:
#    "command to start"
#       associated key
#
#
# A list of keys is in /usr/include/X11/keysym.h and in
# /usr/include/X11/keysymdef.h
# The XK_ is not needed.
#
# List of modifier:
#   Release, Control, Shift, Mod1 (Alt), Mod2 (NumLock),
#   Mod3 (CapsLock), Mod4, Mod5 (Scroll).
#

# The release modifier is not a standard X modifier, but you can
# use it if you want to catch release events instead of press events

# By defaults, xbindkeys does not pay attention with the modifiers
# NumLock, CapsLock and ScrollLock.
# Uncomment the lines above if you want to pay attention to them.

#keystate_numlock = enable
#keystate_capslock = enable
#keystate_scrolllock= enable

# Examples of commands:

#"xbindkeys_show" 
#  control+shift + q

# set directly keycode (here control + f with my keyboard)
#"xterm"
#  c:41 + m:0x4

# specify a mouse button
#"xterm"
#  control + b:2

#"xterm -geom 50x20+20+20"
#   Shift+Mod2+alt + s
#
## set directly keycode (here control+alt+mod2 + f with my keyboard)
#"xterm"
#  alt + c:0x29 + m:4 + mod2
#
## Control+Shift+a  release event starts rxvt
#"rxvt"
#  release+control+shift + a
#
## Control + mouse button 2 release event starts rxvt
#"rxvt"
#  Control + b:2 + Release

# mpd start
#"gnome-terminal --window-with-profile=mpd -e ncmpc"
#    c:237

# mpd start
"gnome-terminal --window-with-profile=mpd -e ncmpc"
    Mod2+Mod4 + y

# gnome terminal
"gnome-terminal"
    Mod2+Mod4 + t

#firefox
"firefox"
   Mod2+Mod4 + i

#mpd-----------------------------------

#play/pause
"mpc toggle"
    Mod2+Mod4 + Up

#stop
"mpc stop"
    Mod2+Mod4 + Down

#next
"mpc next"
    Mod2+Mod4 + Right

#previous
"mpc prev"
    Mod2+Mod4 + Left

#next
"mpc seek +5"
    Control+Mod2+Mod4 + Right

#previous
"mpc seek -5"
    Control+Mod2+Mod4 + Left

#archiv----------------

#state01 mit analog
#"alsactl -f /etc/asound01.state restore"
#    Control+Mod2 + KP_Add

#state02 ohne analog
#"alsactl -f /etc/asound02.state restore"
#    Control+Mod2 + KP_Subtract

#tvtime
#"/home/stefan/Documents/linux-scripts/tvtime+alsactl.sh"
#   Mod2+Mod4 + f

# mpd start mit tastatur und analog aus
#"gnome-terminal --window-with-profile=mpd -e ncmpc" ohne analog aus
#"/home/stefan/Documents/linux-scripts/mpd+alsactl.sh"
#    Mod2+Mod4 + s

##################################
# End of xbindkeys configuration #
##################################

References

http://www.nongnu.org/xbindkeys/ – project’s homepage http://wiki.ubuntuusers.de/xbindkeys – ubuntuusers article wiki

Author: Stefan Schwaha

-<>-

Leave a Reply