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

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 }

Replies are listed 'Best First'.
Re: Reading all nonblocking keystrokes in Win2000
by Washizu (Scribe) on Nov 16, 2001 at 18:17 UTC

    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")

        Thanks for the tip on how to call the function. I found the source for ReadKey.xs, which contains Win32PeekChar(). The problem is that I haven't figured out how to replace ReadKey.xs. I found the file on the web, not on my machine, so I'm not sure where it is stored or compiled. It must be somewhere, but I'm not quite sure yet.

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