Term::ReadKey:术语:: ReadKey :: ReadKey:为什么MS Windows的行为与Linux不同?
#!/usr/bin/env perl
use warnings;
use 5.012;
use Term::ReadKey;
my $key;
ReadMode 4;
print "Enter a key: ";
$key = ReadKey();
printf "|%s|\n", $key // 'undef';
$key = ReadKey(-1);
printf "|%s|\n", $key // 'undef';
$key = ReadKey(-1);
printf "|%s|\n", $key // 'undef';
ReadMode 0;
say "END";
当我运行在Windows或Linux这个脚本的按k
我得到两次这样的输出:
Enter a key: |k|
|undef|
|undef|
END
当我按下Up
“钥匙” 我得到
Enter a key: |
|[|
|A<
END
在Linux上,但在Windows上脚本停顿:
Enter a key:
为什么我在这里不是一些奇怪的标志呢?
该文档听起来更加乐观:“其中一个主要目标是让功能尽可能便携,因此您可以在任何体系结构中插入”使用Term :: ReadKey“,并具有良好的工作可能性。 ' – 2012-04-16 17:56:00