POE::Wheel::TermKey - terminal key input using libtermkey with POE
POE::Wheel::TermKey
libtermkey
POE
use Term::TermKey qw( FORMAT_VIM KEYMOD_CTRL ); use POE qw(Wheel::TermKey); POE::Session->create( inline_states => { _start => sub { $_[HEAP]{termkey} = POE::Wheel::TermKey->new( InputEvent => 'got_key', ); }, got_key => sub { my $key = $_[ARG0]; my $termkey = $_[HEAP]{termkey}; print "Got key: ".$termkey->format_key( $key, FORMAT_VIM )."\n"; # Gotta exit somehow. delete $_[HEAP]{termkey} if $key->type_is_unicode and $key->utf8 eq "C" and $key->modifiers & KEYMOD_CTRL; }, } ); POE::Kernel->run;
This class implements an asynchronous perl wrapper around the libtermkey library, which provides an abstract way to read keypress events in terminal-based programs. It yields structures that describe keys, rather than simply returning raw bytes as read from the TTY device.
This class is a subclass of POE::Wheel, which internally uses an instance of Term::TermKey to access the underlying C library. For details of on general operation, including the representation of keypress events as objects, see the documentation on Term::TermKey instead.
Term::TermKey
Proxy methods exist for normal acessors of Term::TermKey, and the usual behaviour of getkey or other methods is instead replaced by the InputEvent.
getkey
InputEvent
Returns a new instance of a POE::Wheel::TermKey object. It takes the following named parameters:
Optional. File handle or POSIX file descriptor number for the filehandle to use as the connection to the terminal. If not supplied STDIN will be used.
STDIN
libtermkey flags to pass to the Term::TermKey constructor.
Name of the session event to emit when a key is received. The event will be given a single argument, the Term::TermKey::Key event object, as $_[ARG0].
Term::TermKey::Key
$_[ARG0]
Returns the Term::TermKey object being used to access the libtermkey library. Normally should not be required; the proxy methods should be used instead. See below.
These methods all proxy to the Term::TermKey object, and allow transparent use of the POE::Wheel::TermKey object as if it was a subclass. Their arguments, behaviour and return value are therefore those provided by that class. For more detail, see the Term::TermKey documentation.
Paul Evans <leonerd@leonerd.org.uk>
To install POE::Wheel::TermKey, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Wheel::TermKey
CPAN shell
perl -MCPAN -e shell install POE::Wheel::TermKey
For more information on module installation, please visit the detailed CPAN module installation guide.