Question

This works for the key-presses but not for mouse-clicks. What should I change here to make it work (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 ), ">";
    }
}
Was it helpful?

Solution

When I activate the mouse-mode it works.

#!/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";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top