Trucs libres

CV Diaspora
spacer

Écouter les événements souris sous Linux en mode texte

Par dooblem le samedi 8 septembre 2012, 23h59 - Lien permanent

  • Linux
  • MPD
  • Raspberry Pi

Un petit script pour écouter les événements souris avec la commande mev utilisant gpm (General Purpose Mouse).

Utilisé sur mon Raspberry Pi pour lancer des commandes MPD (Music Player Daemon), pour utilisé la souris comme télécommande.

Je n’ai pas encore trouvé comment isolé les événements de la molette souris, pour pouvoir régler le volume. Quelqu’un a une idée ?

Sous Archlinux, vous pouvez ajouter la commande suivante dans /etc/rc.local pour le lancer au boot :

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

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

Fil des commentaires de ce billet

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.