在konsole上读取鼠标事件
#!/usr/bin/env perl
use warnings;
use 5.012;
binmode STDOUT, ':encoding(UTF-8)';
use Term::ReadKey;
sub getch {
my $tty_in = shift;
my $c = ReadKey 0, $tty_in;
if ( $c eq "\e" ) {
my $c = ReadKey 0.10, $tty_in;
if ( $c eq '[' ) {
my $c = ReadKey 0, $tty_in;
if ( $c eq 'M' ) {
my $event_type = ord( ReadKey 0, $tty_in ) - 32;
my $x = ord( ReadKey 0, $tty_in ) - 32;
my $y = ord( ReadKey 0, $tty_in ) - 32;
return $x, $y;
}
}
}
}
#--------------------------------------------------------------
open my $tty_in, '<:encoding(utf-8)', '/dev/tty' or die $!;
Term::ReadKey::ReadMode 'ultra-raw', $tty_in;
# enter_mouse_mode
close $tty_in;
open $tty_in, '<:bytes', '/dev/tty' or die $!;
print "\e[?1003h"; # sets SET_ANY_EVENT_MOUSE mode
my( $x, $y ) = getch( $tty_in );
# leave_mouse_mode
close $tty_in;
open $tty_in, '<:encoding(utf-8)', '/dev/tty' or die $!;
print "\e[?1003l"; # cancels SET_ANY_EVENT_MOUSE mode
Term::ReadKey::ReadMode 'restore', $tty_in;
close $tty_in;
#----------------------------------------------------------------
say "x = $x";
say "y = $y";
我尝试将标记部分从“open $tty_in”移动到“STDIN”,但它还不起作用。 当“x”变得大于“95”(127-32)时,我收到一条错误消息(utf8“\x80”在(eval 1)行没有映射到Unicode...)。 我必须如何修改替换部件才能使其正常工作?
binmode STDIN, ':encoding(utf-8)' or die $!;
Term::ReadKey::ReadMode 'ultra-raw';
# enter_mouse_mode
binmode STDIN, ':bytes' or die $!;
print "\e[?1003h";
my( $x, $y ) = getch( *STDIN );
# leave_mouse_mode
binmode STDIN, ':encoding(utf-8)' or die $!;
print "\e[?1003l";
Term::ReadKey::ReadMode 'restore';
#!/usr/bin/env perl
use warnings;
use 5.012;
binmode STDOUT, ':encoding(UTF-8)';
use Term::ReadKey;
sub getch {
my $tty_in = shift;
my $c = ReadKey 0, $tty_in;
if ( $c eq "\e" ) {
my $c = ReadKey 0.10, $tty_in;
if ( $c eq '[' ) {
my $c = ReadKey 0, $tty_in;
if ( $c eq 'M' ) {
my $event_type = ord( ReadKey 0, $tty_in ) - 32;
my $x = ord( ReadKey 0, $tty_in ) - 32;
my $y = ord( ReadKey 0, $tty_in ) - 32;
return $x, $y;
}
}
}
}
#--------------------------------------------------------------
open my $tty_in, '<:encoding(utf-8)', '/dev/tty' or die $!;
Term::ReadKey::ReadMode 'ultra-raw', $tty_in;
# enter_mouse_mode
close $tty_in;
open $tty_in, '<:bytes', '/dev/tty' or die $!;
print "\e[?1003h"; # sets SET_ANY_EVENT_MOUSE mode
my( $x, $y ) = getch( $tty_in );
# leave_mouse_mode
close $tty_in;
open $tty_in, '<:encoding(utf-8)', '/dev/tty' or die $!;
print "\e[?1003l"; # cancels SET_ANY_EVENT_MOUSE mode
Term::ReadKey::ReadMode 'restore', $tty_in;
close $tty_in;
#----------------------------------------------------------------
say "x = $x";
say "y = $y";
I tried to move the marked part from "open $tty_in" to "STDIN", but it doesn't work yet.
When "x" gets bigger then "95"(127-32) I get an error-message (utf8 "\x80" does not map to Unicode at (eval 1) line ...).
How do I have to modify the replacement-part to get it work?
binmode STDIN, ':encoding(utf-8)' or die $!;
Term::ReadKey::ReadMode 'ultra-raw';
# enter_mouse_mode
binmode STDIN, ':bytes' or die $!;
print "\e[?1003h";
my( $x, $y ) = getch( *STDIN );
# leave_mouse_mode
binmode STDIN, ':encoding(utf-8)' or die $!;
print "\e[?1003l";
Term::ReadKey::ReadMode 'restore';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须改变
with
或 with
然后它就起作用了。
I have to change
with
or with
then it works.