[Ilugc] xbindkeys for X hotkey bindings

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Sat Sep 5 10:17:54 2009

xbindkeys is very easy to use when you wish to bind hotkey presses on
X sessions. Either when you are on a xterm or otherwise.

You have be within the Xwindow session, that is all. Typical Xwindow
sessions span multiple virtual displays or workspaces and typically on
linux you have Xwindow running on virtual terminal Alt + Ctrl + F7.
Anyway I think you know what I mean.

Graphical displays that run something like KDE or Gnome.

There are several key differences between hotkeys in X and text
consoles which we saw with loadkeys(1).

    o Xwindow allows keybindings with mouse buttons (3 buttons are possible)

    o Xwindow keybindings follow a hierarchical model of bindings. For
instance, Firefox will not get a keybinding directly. It has to be
passed by the window manager. That is why I find that sometimes
firefox bindings get intercepted by the windowmanager. You have a
daisy chain of hotkey handlers in the X environment. But this not a
problem with xbindkeys.

    o Xwindow permissions and bindings are user specific. You don't
have to be root to set a keymap like loadkeys

    o You have to install xbindkeys

Okay enough  theory and background.

I created a default keybindings file with

$ xbindkeys --defaults > $HOME/.xbindkeysrc

The syntax is braindead simple.

"pidgin"
  Control + b2 + Release

if you want to invoke pidgin when you press Ctrl key on the keyboard
with the second mouse button.

But things get complicated. You have to know keycodes. You can easily
find that by running

$ xbindkeys -k

It throws up a small white screen a la xev and you will know which
keycode corresponds to which key.

After that just start the xbindkeys daemon with

$ xbindkeys

Every time you change a binding you have to restart this daemon or
send the HUP signal.

$ pkill -HUP xbindkeys

I find that you can create a long command as a shell script
and then bind it. That is more useful to me from a practical
point of view.

For instance,

I create a /bin/playaudio file like this.

   #!/bin/sh
   mplayer /home/music/file1.mp3

 And then chmod it.

# chmod +x /bin/playaudio

Then configure xkeybindings file like this.

"playaudio"
 Mod_M + b1

This will play a song when I press the useless Windows key along with
mouse button 1.

Please refer to the command I gave above to figure out keycodes and
keynames. It is very useful.

Hope this is useful.

I tried this morning and everything worked like a charm. As I expected
this was a very easy affair.

Best,
Girish
-- 
Gayatri Hitech
web: http://gayatri-hitech.com

SpamCheetah Spam filter:
http://spam-cheetah.com

Other related posts:

  • » [Ilugc] xbindkeys for X hotkey bindings - Girish Venkatachalam