NSLU2 Tools: keyevent


'keyevent' is a little tool derived from evtest.c to report keys being pressed or released on a selectable hardware device. It uses the Linux kernel's event interface, so be sure to load the evdev kernel module (modprobe evdev) before using keyevent.

An example for the tool's output:

Double-clicking with the right button of a mouse:

> src/keyevent 09da 0006
Looking for device PID=09da VID=0006
Found event device #2
RightBtn pressed
RightBtn released
RightBtn pressed repeat
RightBtn released

For my Trust USB Sound Card pressing the MUTE button looks like:

> src/keyevent 145f 0090
Looking for device PID=145f VID=0090
Found event device #2
Mute pressed
Mute released

Ok, that's nice but not so useful without any application interpreting the output. The example below implements a shell script to control the Music Player Daemon (MPD) using just the MUTE button on the USB sound card mentioned above.



cmd_repeat="echo -e 'repeat 1\nclose' | nc $MPD_HOST $MPD_PORT > /dev/null"
cmd_playing="echo -e 'status\nclose' | nc $MPD_HOST $MPD_PORT | grep state: | grep -q play"
cmd_next="echo -e 'next\nclose' | nc $MPD_HOST $MPD_PORT > /dev/null"
cmd_stop="echo -e 'stop\nprevious\nclose' | nc $MPD_HOST $MPD_PORT > /dev/null"
cmd_play="echo -e 'play\nclose' | nc $MPD_HOST $MPD_PORT > /dev/null"

eval $cmd_repeat

keyevent $VID $PID 5000 1000 1000 10000 | \
( while :
    read key state rep
    echo $key $state $rep
    if [ "$state" = "pressed" ]
      if [ "$rep" = "double" ]
        if eval $cmd_playing
          echo "stopping"
          eval $cmd_stop
        # single key press
        if eval $cmd_playing
          echo "next song"
          eval $cmd_next
          echo "starting"
          eval $cmd_play
  done )

Pressing the button once turns the player on ("PLAY") or, if it is already playing, skips to the next song in the playlist ("NEXT"). Pressing the button twice within 1 second stops the player ("STOP").

keyevent 0.3 Source Code
keyevent 0.1 Source Code (outdated)
keyevent 0.1 BitBake Package

The packages are also available on my SlugOS/BE 3.10b feed. Follow these instructions (as root):

  1. Log into your NSLU2 and add the DevBase feed:
    # echo "src/gz devbase http://feed.devbase.at/slugos-3.10" > /etc/ipkg/01-devbase-feed.conf
  2. Update the package database:
    # ipkg update
  3. Install some package:
    # ipkg install some-package
3 Kommentare bisher (eigenen Kommentar verfassen)
[1] maybe you could help me with madplay+musicbrowser?
Eingetragen von João am Samstag, 23.08.2008 @ 05:24
I have very basic knowledge of linux environment;still, I maanaged to install on my slug (unslung v. 5.5 beta) lighttpd and php-fcgi and then => mpd+madplay and the web front-end musicbrowser (php). It works fine with my usb philips speakers (I bought a sound usb-dongle for use with the slug). I just lack basic control from my laptop, e.g. to adjust the sound volume of the player from the web interface (from musicbrowser)...Is it possible to adapt a script so it could interact with the keyboard of a machine connected to the lan so it would be possible what I want?

If you have a little moment, I will appreciate any hint or sugestion from you
[2] 5.1 working on Trust USB device?
Eingetragen von alan am Dienstag, 13.01.2009 @ 05:50
Hi there,

Great setup - I have a very similar home setup with my NSLU2, but haven't yet got the 5.1 sound working on my Trust USB sound card (same as yours). Have you got it working?

Antwort von Thomas: Hi Alan,
a few months ago I moved my sound card from the NSLU2 to the QNAP TS-109 II. However I can confirm the following:
  • On the slug 2.0 was working fine.
  • Also on the slug I used dmix to create 2 independent virtual 2.0 sound cards where one was connected to the stereo and the other one to the mini-speaker (shown in my pictures). That also worked fine but create ~15% additional CPU usage by dmix. So after a year I bought a small dedicated CMedia sound card for the speaker.
  • I just tried "speaker-test" on the TS109 and it works fine in a 5.1 setup. I did not check whether there was an actual signal on the respective outputs though. This is without any /etc/asound.conf or ~/.asoundrc file, the ALSA lib and utils are version 1.0.17, kernel is 2.6.27.
So I would guess 5.1 sound should also work on the NSLU2. Do you use some special ALSA configuration? Is there a meaningful error message when you try something like "speaker-test -D plughw:0 -c 6 -f 48000"?

Best regards,
[3] thanks
Eingetragen von Coleman am Freitag, 13.02.2009 @ 07:06
hi i just wanted to leave you a message saying how much i really appreciate this software. im currently using this on my headless box and im using it with a psone controller to run/kill tasks when i want them to run.

thanks again for your hard work, good effort :)
Eigenen Kommentar verfassen

Anmerkung: Die Email-Adresse ist optional und wird nicht veröffentlicht oder auf irgendeine Art weiterverwendet. Bitte nur sachbezogene Kommentare verfassen, anstößiger Inhalt wird entfernt.

HTML-Code ist nicht erlaubt. Zeilenumbrüche werden automatisch erzeugt. URLs werden in Links umgewandelt. Zur Formatierung bitte BBCode verwenden. Beispiele:
[b]fett[/b] ... fett
[code]Quelltext[/code] ... Quelltext

The author does not take any responsibility for problems and damage arising by installing or using this software, use it at your own risk.