#!/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";
When I run this script on Windows or Linux an press k I get both times this output:
Enter a key: |k|
|undef|
|undef|
END
When I press the Up “key” I get
Enter a key: |
|[|
|A<
END
on Linux, but on Windows the script comes to standstill:
Enter a key:
Why do I get here not some strange signs instead?
Simply put, Term::ReadKey assumes Unixy terminals, which Windows doesn’t provide (unless you use Cygwin).
You might try Win32::Console instead. Or there may be some incantations that will get Term::ReadKey to work–good luck on that.