这适用于按键,但不适用于鼠标点击。我应该在这里做些什么才能使其发挥作用(Term::TermKey)?
#!/usr/bin/env perl
use warnings;
use 5.12.0;
use utf8;
use Term::TermKey qw(FLAG_UTF8);
my $tk = Term::TermKey->new( \*STDIN );
binmode STDOUT, ':encoding(utf-8)' if $tk->get_flags & FLAG_UTF8;
while( 1 ) {
my $key;
$tk->waitkey( $key );
if ( $key->type_is_mouse ) {
my ( $ev, $button, $line, $col ) = $tk->interpret_mouse( $key );
say "event : $ev";
say "button: $button";
say "line : $line";
say "col : $col";
}
else {
say "<", $tk->format_key( $key, 0 ), ">";
}
}
答案 0 :(得分:2)
当我激活鼠标模式时,它可以正常工作。
#!/usr/bin/env perl
use warnings;
use 5.12.0;
use utf8;
use Term::TermKey qw(FLAG_UTF8);
my $tk = Term::TermKey->new( \*STDIN );
binmode STDOUT, ':encoding(utf-8)' if $tk->get_flags & FLAG_UTF8;
$|++;
print "\e[?1003h";
say "Quit with \"q\"";
while( 1 ) {
my $key;
$tk->waitkey( $key );
if ( $key->type_is_mouse ) {
my ( $ev, $button, $line, $col ) = $tk->interpret_mouse( $key );
say "event : $ev";
say "button: $button";
say "line : $line";
say "col : $col";
}
else {
say "<", $tk->format_key( $key, 0 ), ">";
last if $tk->format_key( $key, 0 ) eq 'q';
}
}
print "\e[?1003l";