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

I'm looking for a general clue on how Perl might be able to communicate directly with an OS, Windows98 in my case. This question comes from a problem I had yesterday trying to figure out how Perl might be able to detect a single keystroke on the keyboard. Obviously, the CPU and the OS knows that something was typed because a character appears in the terminal but Perl remains oblivious to any keyboard activity until the user presses the return key. The POSIX module apparently won't help me in this case because Windows 98 because it's not POSIX compliant, as far as I could tell.

Note that I'm not looking for any specific answers to the problem above, I'm just wondering about the big picture. How can you get Perl to interface directly with the OS? What are the tools and knowledge that you would need to make that happen?

Any pointers to tutorials, books, ect. that would be helpful to me would be much appreciated.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Perl and the OS
by grinder (Bishop) on Jul 27, 2001 at 19:23 UTC
    sniper (paris' resident Win32 perl hacker) is working on a module to do this sort of stuff, but I don't know how far along the track he is with it. He did post a snippet to detect Ctrl-Alt-Del a while back. I daresay he has similar tricks in waiting.

    --
    g r i n d e r
Re: Perl and the OS
by Moonie (Friar) on Jul 27, 2001 at 19:25 UTC
Re: Perl and the OS
by earthboundmisfit (Chaplain) on Jul 27, 2001 at 19:02 UTC
      Unfortunately, those modules are written with a Unix paradigm in mind, not a Windows one. And, even more unfortunately for you, doing a super-search for "Win32" yields a node called "Win32", which doesn't do what I wanted.

      The best thing to do would be to study the Win32:: module library. There is a book Learning Perl on Win32 which, while very basic, will give you a lot of insight in the Perl + Win32 mindset. I read it and it has a lot of good module stuf. I suggest picking it up.

Re: Perl and the OS
by gwhite (Friar) on Jul 27, 2001 at 21:19 UTC
    win32::console will allow you to retrieve a single keystroke, not dependent on enter.

    g_White
Re: Perl and the OS
by trantor (Chaplain) on Jul 27, 2001 at 23:05 UTC

    One very effective way to get Perl to talk directly with the underlying OS is using glue code written in C, which is very good at dealing with the OS. Extending Perl with C code is typically done through XSUBs (eXternal SUBroutines).

    Some useful resources:

    • perldoc perlxs
    • perldoc perlxstut
    • Chapter 21 of the Camel Book
    • searching xs here

    -- TMTOWTDI