in reply to Re: Reading all nonblocking keystrokes in Win2000
in thread Reading all nonblocking keystrokes in Win2000

Term::ReadKey uses Win32Peek(), but could anyone explain exactly how to use this subroutine anywhere else? I don't know how it is being called since it isn't defined in the Term::ReadKey package or any of the modules it uses (as far as I could tell).

-----------------------------------
Washizu
The best offense is a good offense.

  • Comment on Re: Re: Reading all nonblocking keystrokes in Win2000

Replies are listed 'Best First'.
Re: Re: Re: Reading all nonblocking keystrokes in Win2000
by clintp (Curate) on Nov 16, 2001 at 09:47 UTC
    You shouldn't need to bother with Win32Peek() at all. It's probably just a fancy-ass timed wrapper for getc(). Since Google doesn't seem to think it's part of the Win32 API it's probably something that the Term::ReadKey author whipped up to do timed reads.

    What happens when you get a zero-byte and then do a second ReadKey() right away? Kinda like (pseudocode):

    c=ReadKey if (c==0) { # Oh, this is a special key c=ReadKey }

      I tried the following:

      #!/usr/local/bin/perl5 # Use Perl 5 use Term::ReadKey; my $c = ""; ReadMode(5); while ($c ne "q") # Press q to exit { $c = ReadKey(-1); if (ord($c) == 0) { $c .= ReadKey(-1); } if ($c ne "") { print ord $c; } } ReadMode(0);

      It didn't seem to work. How can Win32Peek() be hidden? I didn't even know this was possible in perl. There are a few things that bother me about Term::ReadKey:

      1. Win32Peek() is somehow both hidden from view, but I can't figure out how to even call it from another script.
      2. I am not sure where the ReadKey subroutine returns a value in the Win32 ReadKey sub. (Can you return a value by putting data into @_?)

      -----------------------------------
      Washizu
      The best offense is a good offense.

        You need to grab the source for the Term::ReadKey module and look at the *.xs file(s), which contain C code. This is almost certainly where you will find Win32Peek().

        What I find is Win32PeekChar() which it appears that you can call like:

        require Term::ReadKey; my $char= Term::ReadKey::Win32PeekChar(STDIN,-1);

                - tye (but my friends call me "Tye")