Beagleboard user button to activate some software

The USER button on the Beagleboard appears as /dev/input/event0 when running Angstrom. That device produces 32 bytes of output at every press or release event. One of them, at offset 12, becomes either 0 or 1 (character “\x00” or “\x01”) when the button is respectively released or pressed.

So I start at every boot this small Ruby script (if you did not yet install Ruby then use apt-get install ruby on Ubuntu or opkg install ruby if Angstrom):

#!/usr/bin/env ruby

fp = File.new "/dev/input/event0"
while fp.read(32)[12] == "\x01"
end
system "halt"

(change halt with the command you want to execute when the user button is pressed; some fiddling with “DISPLAY=:0.0” could allow you to start an X11 program). Since that read is a “blocking I/O”, that while loop won’t cost resources.

Yes, it works.
No, I don’t know how to do it in Python.