A small script to listen to mouse events with the mev command using gpm (General Purpose Mouse).
Can be used for example on the Raspberry Pi to run mpd commands, to use a mouse as a remote control.
I didn’t find how to isolate the wheel events in order to control the volume. Any idea somebody?
In Archlinux, you can add the following command in /etc/rc.local to start it at boot time:
nohup /usr/local/bin/mpd_mouse.sh > /tmp/mpd_mouse.log 2>&1 &
#!/bin/sh
# This script listen to mouse events with the mev command using gpm.
# Can be used for example on the Raspberry Pi to run mpd commands, to use a mouse as a remote control.
# You can start it as a daemon with:
# nohup /usr/local/bin/mpd_mouse.sh > /tmp/mpd_mouse.log 2>&1 &
# start gpm if not already started
gpm -m /dev/input/mice -t imps2
# unset TERM variable, otherwise mev refuses to start when detecting xterm
unset TERM
echo "Listening to mouse events..."
# we use script to fake a tty for mev, otherwise it exits (note: mev logs errors in syslog)
script -qc "mev -E" /dev/null </dev/null | grep --line-buffered -v "mouse-movement" | while read LINE
do
echo
echo "$LINE"
EVENT=$(echo "$LINE" | cut -d' ' -f1 | cut -d'(' -f2)
if [ "$EVENT" = "down-mouse-1" ]
then
echo mpc stop
mpc stop
elif [ "$EVENT" = "down-mouse-2" ]
then
echo mpc toggle
mpc toggle
elif [ "$EVENT" = "down-mouse-3" ]
then
echo mpc next
mpc next
else
echo "nothing"
fi
done



Thanks a lot!
I will be fighting with “cat /dev/input/mice | od -An -t x1 -w1″ and correlats, but your solution works better.
Congratulations!