#!/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 版本是什么?根据changelog ,最近添加了扩展鼠标模式(版本262)。你的代码对我来说适用于 xterm 266,perl 5.10。我无法通过一些简单的策略(LANG=C xterm
、xterm +lc
禁用区域设置支持)来打破它。
关于perl - 如何启用扩展鼠标模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4681302/