2012-04-20 121 views
0

這適用於按鍵,但不適用於鼠標點擊。我應該改變什麼才能使其工作(Term::TermKey)?Term :: TermKey:捕捉mouseevents和按鍵的正確方法是什麼?

#!/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

binmode STDOUT,':encoding(utf-8)'if if $ tk-> get_flags&FLAG_UTF8; 你可能的意思是'編碼(UTF-8)'這裏 – LeoNerd 2012-04-21 22:50:29

+0

我認爲它們是等價的。 – 2012-04-22 06:00:49

+0

首都'UTF-8'。 – LeoNerd 2012-04-22 22:48:13

回答

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"; 
+0

就是這樣。 'libtermkey'可以識別鼠標事件,如果它接收到它們,但由於它最初不會與終端通信,所以它不能啓用鼠標模式。你的DEC模式1003就足夠了。 – LeoNerd 2012-04-21 22:48:02

相關問題