Sioln has asked for the wisdom of the Perl Monks concerning the following question:

use Term::ReadKey; my $key; while (not defined ($key = ReadKey(-1))) { # No key yet } print "Get key '$key'\n"; print ord($key); print "\n"; print chr($key);
This code catches any key but PgUp, PgDn, func keys - not :( How can I got PgUp with Term::ReadKey ? Please, don't offer me a WIN32::Console. I need do it on term. P.S. OS = Windows 2000. Sioln.

Replies are listed 'Best First'.
Re: Term::ReadKey - How can I get PgUp, PgDn etc ?
by gellyfish (Monsignor) on Aug 17, 2005 at 12:46 UTC

    Given a particular terminal type ReadKey() may need to be called repeatedly to retrieve a multicharacter code for a given control key - so for instance on an xterm on this computer I could use something like:

    use Term::ReadKey; my $key = ''; ReadMode(4); + my %keys = ( A => 'KeyUp', B => 'KeyDown', C => 'KeyRight', D => 'KeyL +eft'); while ($key ne 'q' ) { while (not defined ($key = ReadKey(-1))) { # No key yet } + if ( ord($key) == 27 ) { if( ReadKey(-1) eq '[' ) { $key = ReadKey(-1); + print $keys{$key},"\n"; } } } print "\n"; ReadMode(0);
    You may of course have to adjust some of the values to work on your system.

    /J\

      That doesn't apply to windows.
Re: Term::ReadKey - How can I get PgUp, PgDn etc ?
by davidrw (Prior) on Aug 17, 2005 at 12:36 UTC
    Hmm.. i know that the special chars are usually a two-character sequence.. doing ReadKey() twice didn't work for me though. I did find an entry in the FAQ though (perldoc perlfaq5): 'How can I read a single character from a file? From the keyboard?' but i didn't immediately get a working test case. I also found this node Term::TermKeys here on PM that looks promising...