Mapping keyboard buttons using xbindkeys; OSD with MOC Player

kategorie: howto
publikoval: robo
datum a čas: 08-10-2005 19:29:38

I have a Logitech keyboard with all those nice buttons (volume, mute...) which I decided to finally put to use (I have been having this keyboard for more than two years) today morning. The exact model name is "Cordless desktop optical" or simply "Y-RK49".

At one point I used lineak which is great and if you want something as simple as possible go with it. Following setup should be more fun though, at least it was for me.

I use moc player (with ALSA) for playing my ogg and mp3 files and gentoo as distribution.

If you have another keyboard model it should work too. Run xev command in terminal and press those special buttons. If xev logs its output you should be safe.


First, install xbindkeys. In gentoo it's as simple as:

$ emerge xbindkeys

We need configuration file so download the example from xbindkeys homepage:

$ cd
$ wget
$ mv xbindkeysrc_d .xbindkeysrc

In your favorite editor comment out everything.

Let your editor open with .xbindkeysrc file and open another terminal. Here we will get key codes and copy&paste them into .xbindkeysrc. So run:

$ xbindkeys --key

Now press key for which you desire to increment Volume for example. Mine shows this:

	m:0x10 + c:176
	Mod2 + NoSymbol

So I put into .xbindkeysrc:

# volume +
"amixer sset Master 3+"
        m:0x10 + c:176
        Mod2 + NoSymbol

amixer is ALSA utility which allows you to control your mixer settings. If you use OSS there are plenty of mixers available too, for example aumix.

This way fill your .xbindkeysrc file. Mine is here:

# media
"aterm -geometry 80x50 -bg black -fg white -e mocp &"
        m:0x10 + c:129
        Mod2 + NoSymbol

# ctrl + media 
        m:0x14 + c:129
        Control+Mod2 + NoSymbol

# play/pause
"mocp --toggle-pause"
        m:0x10 + c:162
        Mod2 + NoSymbol

# mute
"amixer sset Master toggle"
        m:0x10 + c:160
        Mod2 + NoSymbol

# volume -
"amixer sset Master 3-;/home/robo/bin/"
        m:0x10 + c:174
        Mod2 + NoSymbol

# volume +
"amixer sset Master 3+;/home/robo/bin/"
        m:0x10 + c:176
        Mod2 + NoSymbol

# ctrl + volume -
"amixer sset Master 1-;/home/robo/bin/"
        m:0x14 + c:174
        Mod2 + NoSymbol

# ctrl + volume +
"amixer sset Master 1+;/home/robo/bin/"
        m:0x14 + c:176
        Mod2 + NoSymbol

# favorites
"mocp --next"
        m:0x10 + c:230
        Mod2 + NoSymbol

# e-mail
"aterm -geometry 100x50 -bg black -fg white -e mutt"
        m:0x10 + c:236
        Mod2 + NoSymbol

# www
        m:0x10 + c:130
        Mod2 + NoSymbol

Now the basic setup should be working.

OSD Volume bar

I'll stop talking (I'm already scared off of my English) and will just paste the script


# slider or percentage

VOLUME=`amixer get Master | grep Front.Left\: | \
sed -e s/"  Front Left: Playback [0-9]* \["// | sed -e s/"\%.*"//`

osd_cat --offset=10 --indent=10 --color=$COLOR --shadow=$SHADOW \
--barmode=$BARMODE --percentage=$VOLUME --delay=1

Save this script somewhere and add it to your .xbindkeysrc like I did in above listing. Here is screenshot.

MOC player and OSD




TOTALSEC=`mocp --info | egrep "TotalSec\:" | sed 's/TotalSec\:\ //'`
CURRENTSEC=`mocp --info | egrep "CurrentSec\:" | \
sed 's/CurrentSec\:\ //'`


mocp --info | \
egrep "^Artist\:|^SongTitle\:|^Album\:" | \
osd_cat --offset=10 --indent=10 --color=$COLOR --font=$FONT \
--shadow=$SHADOW &

osd_cat --offset=120 --indent=10 --color=$COLOR --font=$FONT \
--shadow=$SHADOW --barmode=percentage --percentage=$PERCENT

This script first displays Artist, Song Title, Album items and progress bar below which displays how much of a song has been played so far. Another screenshot.


A lot of people on the Net were inspiration so this is my Thank you! Enjoy your setup and don't hesitate to write me email or let comment down here.


Příprcky jsou duševním vlastnictvím jejich autorů, vše ostatní © 2004 - 2017 by Vygenerováno za 0.042773 sekund