NAME
Linux::USBKeyboard - access devices pretending to be qwerty keyboards
SYNOPSIS
Use `lsusb` to discover the vendor+product id pair.
ABOUT
This module gives you access to usb barcode scanners, magstripe readers, numpads and other "pretend I'm a keyboard" hardware.
It bypasses the keyboard driver so that your dvorak or international keymap won't get in the way. It also allows you to distinguish one device from another, run as a daemon (not requiring X/console focus), and other good things.
CAVEATS
This module assumes that you want the device to use a qwerty keymap. In the case of magstripes and barcode scanners, this is almost definitely the case. A tenkey pad won't matter. For some kind of secondary usermode keyboard (e.g. gaming, etc) maybe you actually want to be able to apply a keymap?
I'm not sure how to let the main hid driver have the device back. You have to unplug it and plug it back in or run `libhid-detach-device`.
Patches welcome.
SETUP
You'll need a fairly modern Linux, Inline.pm, and libhid.
cpan Inline
aptitude install libhid-dev
You should setup udev to give the device `plugdev` group permissions or whatever (rather than developing perl code as root.)
Constructor
new
my $kb = Linux::USBKeyboard->new($vendor_id, $product_id);
_check_args
Hex numbers passed as strings must include the leading '0x', otherwise they are assumed to be integers.
Arguments may also be a hash (vendor => $v, product => $p.)
my ($vendor_id, $product_id) = $class->_check_args(@_);
open
Get a filehandle to a forked process.
my $fh = Linux::USBKeyboard->open($vendor_id, $product_id);
The filehandle is an object from a subclass of IO::Handle. It has the method $fh->pid if you need the process id. The subprocess will be automatically killed by the object's destructor.
I've tested reading with readline($fh) and getc($fh) (both of which will block.) See examples/multi.pl for an example of IO::Select non-blocking multi-device usage.
Methods
char
Returns the character (with shift bit applied.)
print $k->char;
keycode
Get the raw keycode. This allows access to things like numlock, but also returns keyup events (0). Returns -1 if there was no event.
This method is somewhat unreliable in that it can't tell you when a key was pressed while another key is being held down. Consider it alpha.
AUTHOR
Eric Wilhelm @ <ewilhelm at cpan dot org>
http://scratchcomputing.com/
BUGS
If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
If you pulled this development version from my /svn/, please contact me directly.
COPYRIGHT
Copyright (C) 2007 Eric L. Wilhelm, All Rights Reserved.
NO WARRANTY
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.