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

How do you stuff the keyboard buffer from within perl? I have a c program that reads using "getch()" and "kbhit()", and I need the perl program to write the "input" key selection. I've tried open2 and win32::console, print(STDOUT), but none of them work.

Replies are listed 'Best First'.
Re: Stuff the keyboard buffer
by tachyon (Chancellor) on Oct 28, 2004 at 05:33 UTC

    The problem is that you are on Win32 ;-) But seriously your app will be running in a terminal window (tty) or Win32s version thereof. The easiest solution will be to use Win32::GuiTests SendKeys method. A console window is really just another GUI with lots of black stuff. You can check out the XS code if you want to see the underlying code which hooks straight into windows.h

    cheers

    tachyon

Re: Stuff the keyboard buffer
by Kalaspuff (Beadle) on Oct 28, 2004 at 02:10 UTC
    You might want to check out the module Term::ReadKey. I haven't used it myself though but it seems like one way to do it. ;-)