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

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.

Replies are listed 'Best First'.
(tye)Re: Reading all nonblocking keystrokes in Win2000
by tye (Sage) on Nov 19, 2001 at 21:27 UTC

    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.

        *.xs files are turned into *.c files that are then compiled into shared libraries (DLLs on Windows). Read perldoc perlxstut, perldoc perlxs, perldoc perlmod, and perldoc perlmodlib for more information.

        If you want to make (changes to) *.xs code under Windows, then you really want WinNT or later and the same C compiler that was used to build your version of Perl (which means Microsoft Visual C++ unless you have an unusual distribution of Perl installed).

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