0

这适用于按键,但不适用于鼠标点击。我应该在此处更改什么以使其正常工作(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 ), ">";
    }
}
4

1 回答 1

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";
于 2012-04-20T14:13:17.133 回答