redss has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I have a usb keyboard connected, and after adding the evdev to the kernel (modprobe evdev) I have event devices /dev/input/event0,1,2,3 etc

Iwant to find out which event device pertains to the usb keyboard, and I understand that a way is to open the device and check the device ID via ioctl().

In other words, I'd like to see something like the output of lsusb for that particular device.

How would I do that in perl?

Replies are listed 'Best First'.
Re: calling ioctl
by Fletch (Bishop) on Oct 15, 2008 at 00:52 UTC

    Calling ioctls is hairy. Well if not hairy, ugly. You're basically going to have to find out how you'd call the same thing from C and then pack up the required structures and unpack the results. You'd probably be better off either doing the C stuff in C and rolling up a quick interface using Inline::C, or in this specific case see if Device::USB can't take care of all the nasty stuff for you out of the box.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: calling ioctl
by Illuminatus (Curate) on Oct 15, 2008 at 01:33 UTC
    If you can get the information you need from lsusb, then just use that:
    my @output=`lsusb`;
    or
    open LSUSB, "lsusb |" || die "call to lsusb failed: $!"; while (<LSUSB>) { # find what you are looking for }
Re: calling ioctl
by thinc (Novice) on Oct 15, 2008 at 17:34 UTC
    Here is how I lock the CDROM on my laptop (running linux) using an IOCTL
    use IO::File; use Fcntl qw(O_RDONLY O_NONBLOCK); my $CDROM_LOCKDOOR = 0x5329; my $cdrom_dev = '/dev/scd0'; my $cdrom = IO::File->new( $cdrom_dev , O_RDONLY|O_NONBLOCK ) or die " +unable to open $cdrom_dev: $!"; my $ret = ioctl( $cdrom , $CDROM_LOCKDOOR , pack('I',0) );