NAME

Linux::Input - Linux input event interface

SYNOPSIS

Example: 1 joystick using event API

my $js1 = Linux::Input->new('/dev/input/event3');
while (1) {
  while (my @events = $js1->poll(0.01)) {
    foreach (@event) {
    }
  }
}

Example: 2 joysticks using joystick API (different event structure)

my $js1 = Linux::Input::Joystick->new('/dev/input/js0');
my $js2 = Linux::Input::Joystick->new('/dev/input/js1');
my $selector = IO::Select->new();
$selector->add($js1->fh);
$selector->add($js2->fh);

while (my $fh = $selector->can_read) {
  my @event;
  if ($fh == $js1->fh) {
    @event = $js1->poll()
  } elsif ($fh == $js2->fh) {
    @event = $js2->poll()
  }
  foreach (@event) {
    # work
  }
}

Example 3: monitor all input devices

use File::Basename qw(basename);
my @inputs = map { "/dev/input/" . basename($_) }
  </sys/class/input/event*>;

my @dev;
my $selector = IO::Select->new();
foreach (@inputs) {
  my $device = Linux::Input->new($_);
  $selector->add($device->fh);
  push @dev, $device;
}

while (my $fh = $selector->can_read) {
  # work
}

Example 4: testing for events on the command line

# information on what event queue belongs to what device
cat /proc/bus/input/devices

# verify that events are coming in
sudo evtest.pl /dev/input/event*

DESCRIPTION

Linux::Input provides a pure-perl interface to the Linux kernel's input event interface. It basically provides a uniform API for getting realtime data from all the different input devices that Linux supports.

For more information, please read: /usr/src/linux/Documentation/input/input.txt.

Class Methods

new

This method takes one filename as a parameter and returns a Linux::Input object.

Example:

my $js1 = Linux::Input->new('/dev/input/event3');

entity_bytes

This method returns the size of the event structure on this system.

Example:

my $struct_size = Linux::Input->entity_bytes();

timeout

This method can be used to read or specify the default timeout value for the select()'ing on filehandles that happens within the module. The default value is 0.01.

Object Methods

fh

This method returns the filehandle of a Linux::Input object.

Example:

my $filehandle = $js->fh();

selector

This method is used internally to return the IO::Select object that's been assigned to the current Linux::Input object.

poll

This method takes a $timeout value as a parameter and returns a list of @events for the current Linux::Input object. Each event is a hashref with the following key/value pairs.

tv_sec
tv_usec
type
code
value

Example:

my @events = $js->poll(0.01);

AUTHOR

John Beppu (beppu@cpan.org)

SEE ALSO

Linux::Input::Joystick, Class::Data::Inheritable, IO::Select, IO::File