Connecting my multimedia keyboard to mplayer via xbindkeys and bash named pipe
Contents
Problem
How do I get my multimedia keyboard special keys to work on Linux?
Solution
Use xbindkeys: "a program that allows you to launch shell commands with your keyboard or your mouse under X Window.".
Use xbindkeys -mk
to find out the keycodes of the special multimedia keys on your keyboard. For example the play/pause key gives me:
m:0x10 + c:162
Define these keycodes in a file called ~./xbindkeysrc:
#--- .xbindkeysrc ------------------ # Play "/home/freddy/proj/music/mplayer.sh" m:0x10 + c:162
Contents of mplayer.sh (using named pipes):
#!/bin/bash #--- mplayer.sh ------------------- if [ -p /tmp/mplayer ]; then echo -n p > /tmp/mplayer else mkfifo /tmp/mplayer echo -n > /tmp/mplayer & mplayer '/mp3/'* < /tmp/mplayer rm /tmp/mplayer fi
Now other keys can be programmed in .xbindkeysrc to write to the named pipe:
#--- .xbindkeysrc --------------------------------- # ... # Stop "[ -p /tmp/mplayer ] && echo -n q > /tmp/mplayer" m:0x10 + c:164 # Previous "[ -p /tmp/mplayer ] && echo -n '<' > /tmp/mplayer" m:0x10 + c:144 # Next "[ -p /tmp/mplayer ] && echo -n '>' > /tmp/mplayer" m:0x10 + c:153 # Volume down "[ -p /tmp/mplayer ] && echo -n '/' > /tmp/mplayer" m:0x10 + c:174 # Volume up "[ -p /tmp/mplayer ] && echo -n '*' > /tmp/mplayer" m:0x10 + c:176
Journal
20051229
Found thorough description here: HOWTO Use Multimedia Keys - Gentoo Linux Wiki.
20060723
I have a Sweex keyboard, model: EA100011. My .Xmodmap:
keycode 234 = XF86Back keycode 233 = XF86Forward keycode 232 = XF86Stop keycode 231 = XF86Refresh keycode 229 = XF86Search keycode 230 = XF86Favorites keycode 178 = XF86HomePage keycode 236 = XF86Mail keycode 237 = XF86AudioMedia keycode 160 = XF86AudioMute keycode 144 = XF86AudioPrev keycode 162 = XF86AudioPlay keycode 164 = XF86AudioStop keycode 153 = XF86AudioNext keycode 174 = XF86AudioLowerVolume keycode 176 = XF86AudioRaiseVolume keycode 235 = XF86Start keycode 161 = XF86Calculator keycode 222 = XF86PowerOff keycode 223 = XF86PowerDown keycode 227 = XF86WakeUp
http://susewiki.org/index.php?title=Multimedia_Keysz
Can't find package xbindkeys in SuSE 10.0.
Found a package here: http://rpm.pbone.net/index.php3?stat=3&search=xbindkeys&srodzaj=3
20060726
Unable to login because of X errors. And also I want my multimedia keyboard settings to be global.
Found in /usr/X11R6/bin/startx: a local ~/.xinitrc overrides a global /usr/X11R6/lib/X11/xinit/xinitrc.
20061117
- Linux Support for text output
- "How Linux works". Detailed explanation of different levels a key goes though, from terminal to application.
- Fixing or flushing screen after playing MPlayer in svga mode?
- Forum topic with example of creating a fifo (named pipe) to serve as mplayer stdin
- Introduction to Named Pipes
- Clear article explaining named pipes
- tput: Portable Terminal Control
- List of key identifiers to be used with
tput
, e.g. codes for arrow keys