#!/usr/bin/env perl
use warnings;
use 5.012;
use Term::ReadKey;
sub getch {
my $c = ReadKey 0;
if ($c eq "\e") {
my $c = ReadKey 0.10;
if ($c eq '[') {
my $c = ReadKey 0;
if ($c eq 'M') {
my $event_type = ord(ReadKey 0) - 32;
my $x = ord(ReadKey 0) - 32;
my $y = ord(ReadKey 0) - 32;
return $x, $y;
} } } }
binmode STDIN, ':encoding(utf-8)' or die $!;
ReadMode 'ultra-raw';
# enter_mouse_mode
binmode STDIN, ':raw' or die $!;
print "\e[?1003h"; # sets SET_ANY_EVENT_MOUSE mode
my($x, $y ) = getch();
# leave_mouse_mode
binmode STDIN, ':encoding(utf-8)' or die $!;
print "\e[?1003l"; # cancels SET_ANY_EVENT_MOUSE mode
ReadMode 'restore';
say "x = $x";
say "y = $y";
該腳本最多隻能運行223列(223 + 32 - > 1個字節)。
有誰知道,如何啓用extended mouse mode? 我試圖改變鼠標模式的這種方式,但它沒有工作:如何啓用擴展鼠標模式?
# enter_mouse_mode
binmode STDIN, ':utf8' or die $!;
print "\e[?1003h";
print "\e[?1005h"; ###
my($x, $y ) = getch();
# leave_mouse_mode
binmode STDIN, ':encoding(utf-8)' or die $!;
print "\e[?1003l";
print "\e[?1005l"; ###
它現在可以工作(xterm v268) - 我在移動鼠標(不點擊)時已經獲得了結果。但是我忘了提及我正在使用KDE的Konsole,但它仍然無法工作。 – 2011-04-16 09:10:57