| 1 |
NAME |
| 2 |
"AnyEvent::TermKey" - terminal key input using "libtermkey" with |
| 3 |
"AnyEvent" |
| 4 |
|
| 5 |
SYNOPSIS |
| 6 |
use AnyEvent::TermKey qw( FORMAT_VIM KEYMOD_CTRL ); |
| 7 |
use AnyEvent; |
| 8 |
|
| 9 |
my $cv = AnyEvent->condvar; |
| 10 |
|
| 11 |
my $aetk = AnyEvent::TermKey->new( |
| 12 |
term => \*STDIN, |
| 13 |
|
| 14 |
on_key => sub { |
| 15 |
my ( $key ) = @_; |
| 16 |
|
| 17 |
print "Got key: ".$key->termkey->format_key( $key, FORMAT_VIM )."\n"; |
| 18 |
|
| 19 |
$cv->send if $key->type_is_unicode and |
| 20 |
$key->utf8 eq "C" and |
| 21 |
$key->modifiers & KEYMOD_CTRL; |
| 22 |
}, |
| 23 |
); |
| 24 |
|
| 25 |
$cv->recv; |
| 26 |
|
| 27 |
DESCRIPTION |
| 28 |
This class implements an asynchronous perl wrapper around the |
| 29 |
"libtermkey" library, which provides an abstract way to read keypress |
| 30 |
events in terminal-based programs. It yields structures that describe |
| 31 |
keys, rather than simply returning raw bytes as read from the TTY |
| 32 |
device. |
| 33 |
|
| 34 |
It internally uses an instance of Term::TermKey to access the underlying |
| 35 |
C library. For details on general operation, including the |
| 36 |
representation of keypress events as objects, see the documentation on |
| 37 |
that class. |
| 38 |
|
| 39 |
Proxy methods exist for normal accessors of "Term::TermKey", and the |
| 40 |
usual behaviour of the "getkey" or other methods is instead replaced by |
| 41 |
the "on_key" event. |
| 42 |
|
| 43 |
CONSTRUCTOR |
| 44 |
$aetk = AnyEvent::TermKey->new( %args ) |
| 45 |
This function returns a new instance of a "AnyEvent::TermKey" object. It |
| 46 |
takes the following named arguments: |
| 47 |
|
| 48 |
term => IO or INT |
| 49 |
Optional. File handle or POSIX file descriptor number for the |
| 50 |
file handle to use as the connection to the terminal. If not |
| 51 |
supplied "STDIN" will be used. |
| 52 |
|
| 53 |
on_key => CODE |
| 54 |
CODE reference to the key-event handling callback. Will be |
| 55 |
passed an instance of a "Term::TermKey::Key" structure: |
| 56 |
|
| 57 |
$on_key->( $key ) |
| 58 |
|
| 59 |
METHODS |
| 60 |
$tk = $aetk->termkey |
| 61 |
Returns the "Term::TermKey" object being used to access the "libtermkey" |
| 62 |
library. Normally should not be required; the proxy methods should be |
| 63 |
used instead. See below. |
| 64 |
|
| 65 |
$flags = $aetk->get_flags |
| 66 |
$aetk->set_flags( $flags ) |
| 67 |
$canonflags = $aetk->get_canonflags |
| 68 |
$aetk->set_canonflags( $canonflags ) |
| 69 |
$msec = $aetk->get_waittime |
| 70 |
$aetk->set_waittime( $msec ) |
| 71 |
$str = $aetk->get_keyname( $sym ) |
| 72 |
$sym = $aetk->keyname2sym( $keyname ) |
| 73 |
( $ev, $button, $line, $col ) = $aetk->interpret_mouse( $key ) |
| 74 |
$str = $aetk->format_key( $key, $format ) |
| 75 |
$key = $aetk->parse_key( $str, $format ) |
| 76 |
$key = $aetk->parse_key_at_pos( $str, $format ) |
| 77 |
$cmp = $aetk->keycmp( $key1, $key2 ) |
| 78 |
These methods all proxy to the "Term::TermKey" object, and allow |
| 79 |
transparent use of the "AnyEvent::TermKey" object as if it was a |
| 80 |
subclass. Their arguments, behaviour and return value are therefore |
| 81 |
those provided by that class. For more detail, see the Term::TermKey |
| 82 |
documentation. |
| 83 |
|
| 84 |
AUTHOR |
| 85 |
Paul Evans <[email protected]> |
| 86 |
|