Dramatic reveal and USB keyboards

Michael Lush mjlush at gmail.com
Sun Dec 2 17:44:00 GMT 2012


I'm running a tabletop RPG where we keep wanting to play Dramatic
Reveal, Rimshot,
Sad Trombone and the like to punctuate the action.  Looking round
there are many sound
effects boxes but none of them are customizable.

So I thought that's a nice little Make... RasPi + speakers with a
wireless USB numeric keypad
and daemon process to listen for the keypress and play the right file...

Device::USB seemed to be the right place to look however I can get as
far as getting the config data

#!/usr/bin/perl
use strict;
use warnings;
use Device::USB;
use YAML;
my $VENDOR = hex("1d57");
my $PRODUCT = hex('32da');
my $usb = Device::USB->new();
my $dev = $usb->find_device( $VENDOR, $PRODUCT );
print $dev->claim_interface(1);
my $conf = $dev->get_configuration();
print Dump($conf);

But for the life of me can't find out how to listen for keyboard output

The best I can find is

while (1) {
    my $data   = `cat /dev/hidraw2 | head -c 7`;
    my $char = ord(substr($data, 2, 1));
    print "  $char \n";;
}

However this fails if you keep mashing the key it stops reading the
keyboard output.

any pointers?
--
Michael Lush


More information about the london.pm mailing list