Ace128 has asked for the wisdom of the Perl Monks concerning the following question:
According to: http://www.perl.com/doc/manual/html/pod/perlfaq5.html#How_can_I_read_a_single_characte it should be rather correct, but Ive found stuff about some needed ioctl.ph http://www.perl.com/doc/manual/html/pod/perlfunc/ioctl.html aswell... In either case, I'm lost and I was hoping someone could provide me with something that actually works! I don't mind if usage of Win32::API or simulair is used. Running the provided code and pressing a special key gives $ord = 0. So far so good I suppose. But the rest doesn't work. Actually, not even the ioctl hack mentioned first doesn't work. (Returns -1)use Term::ReadKey; use Time::HiRes qw( usleep ); use strict; use warnings; ReadMode(4); my $old_ioctl = ioctl(STDIN,0,0) || -1; # Gets device info printf "System returned %d\n", $old_ioctl; $old_ioctl &= 0xff; ioctl(STDIN,1,$old_ioctl | 32); # Writes it back, setting bit 5 $| = 1; while(1){ my $char; while (!defined ($char = ReadKey(-1))){ usleep 1_100; } my $ord = ord($char); last if ($ord == 3); last if ($ord == 4); last if ($ord == 27); if ($ord == 0) { #my $c; #sysread(STDIN,$c,1); #print "C: $c\n"; } print $ord . "\n"; } $| = 0;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Getting special keys to work with Term::ReadKey in Windows
by gellyfish (Monsignor) on Jul 21, 2006 at 09:34 UTC | |
by Ace128 (Hermit) on Jul 21, 2006 at 12:08 UTC | |
Re: Getting special keys to work with Term::ReadKey in Windows
by Anonymous Monk on Jul 24, 2006 at 07:49 UTC |