Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Win32::Console Input Buffer Problem

by Android 18 (Novice)
on Jul 21, 2002 at 21:25 UTC ( [id://183875]=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying to very simply get key press input from the input buffer using Win32::Console. For some reason, the Input() method always returns a list of one element whose value is "" rather than a list describing the next event. Then when the program exits, all the keypresses are dumped to the command line at once. I've been trying an assortment of different things with the Alloc(), Free(), Select() and Mode() methods. I've read microsoft's documentation on the subject but still am stuck.

On my scratchpad is the source to the module where I'm using Win32::Console right now. Eventually, my whole program will have lots of different modules that have their own Win32::Console objects. Each module will be called to do a specific task. for example this module is going to be a file selector. Anyway, the object of _my_ module is created in the main program with its new() method. After which I call Start() and Title() to set up some stuff and run it with it's Run() method. You can see how Run() calls the MainLoop() and, when I get it working, eventually it'll return a path to a file they select. The problem is in the main loop. If anyone can help me please do. I'm having trouble finding good documentation and examples.

Replies are listed 'Best First'.
Re: Win32::Console Input Buffer Problem
by dada (Chaplain) on Jul 22, 2002 at 09:32 UTC
    your problem is that you're creating a console in memory, and this one isn't tied with STDIN. so it has no ways to catch input events. change your new Win32::Console() line to read: new Win32::Console(STD_INPUT_HANDLE) and you'll get the input as you expect.

    cheers,
    Aldo

    __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;
      I have done something similar so many times... I find Win32::Console incredibly confusing though powerful, and I usually cargo-cult my own old scripts, because otherwise it takes me several hours to set up the input and output channels correctly.

      Which is odd, because the module has extensive documentation: I think that it could do with some sort of cookbook though. I'd be interested in helping out with this, if anyone's interested.

      Cheerio!
      Osfameron
      http://osfameron.perlmonk.org/chickenman/

Re: Win32::Console Input Buffer Problem
by JayBonci (Curate) on Jul 21, 2002 at 22:58 UTC
    As a suggestion, for the future monks who may read your question, please paste your code into your post (or a comment onto the post), for people to peruse. You may not have that code on your scratch pad forever, and people may be plagued by the same problem in the future. Another good suggestion is to surround it with <code></code> tags (In your case, the code was long and needed to be given <readmore> tags. I've taken the liberty and pasted the code here

        --jb
      Thank you, I didn't know about the readmore tags. I'll remember that in the future.

      Once bread becomes toast, it can never be bread again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://183875]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found