sammo2828 wrote:
> How do I read arrow keys (i.e. up, down, left, right) and function keys in
> ActivePerl running on Windows XP?
>
> I tried using Term::ReadKey (see below), but it only prints "0" when I enter
> an arrow key or function key.
>
> use Term::ReadKey;
> ReadMode 4; # Turn off controls keys
> while (not defined ($key = ReadKey(-1))) {
> # No key yet
> }
> print "$key " . ord($key) . "\n";
> ReadMode 0; # Reset tty mode before exiting
I'd go for Win32::Console in this case :
use strict;
use warnings;
use Win32::Console;
my $STDIN = new Win32::Console(STD_INPUT_HANDLE);
$STDIN->Mode(ENABLE_PROCESSED_INPUT);
while (1) {
# Read kybd/mouse event
my @input = $STDIN->Input();
if (defined $input[0] and $input[0] == 1) {
print "Key down : ", $input[1] ? 'yes' : 'no', "\n";
print "Count: $input[2]\n";
print "Key Code: $input[3]\n";
print "Scan Code: $input[4]\n";
print "Key Value: $input[5]\n";
printf "Modifiers flags: %X\n\n", $input[6];
last if $input[3] == 81; # 'q'
next;
} else {
print "Mouse event\n";
}
}
print "exiting\n";
exit 0;
__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs