Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am trying to spoof non-blocking reads on a Win32 client. I have spent a lot of time looking around at various code examples. The vec()..select() method on <STDIN> does not work. ReadLine in TERM::Readkey doesn't work either. but the ReadKey function does. Here is my code;
#!/usr/bin/perl use Term::ReadKey; until ($Name){ print "Your callsign?>"; chomp ($Name = <>); if ($Name) { print "say: !! to exit\n\n"; open (TX, ">>d:/telnet/say.txt"); printf TX time." $Name entered.\n"; close (TX); } } $Lastime = time; while($key.$Input ne "!!"){ open (RX, "<d:/telnet/say.txt"); @Said = <RX>; close (RX); foreach $Said(@Said){ $Said =~ m/(^\d+)(\s[\D \d]*)/; if ($1 >= $Lastime){ print $2; Tmptime = $1; } } $Lastime = $Tmptime + 1; if ($key = ReadKey 2){ print $key; if (ord($key) != 13){ chomp($Input = <>); } else { $key=""; $Input = ""; } open (TX, ">>d:/telnet/say.txt"); printf TX time." $Name said: $key$Input\n"; close (TX); } } open (TX, ">>d:/telnet/say.txt"); printf TX time." $Name left.\n"; close (TX); print "\n\nBye.";
It's a basic realtime chat client. It's not entirely bulletproof and it's not very efficient because it reads the whole say.txt file every 2 seconds. I can work on these limitations later.

The part I really need to fix is; Because the first keypress interrupts the ReadKey block it has to be printed to the console seperately. Thus if the user wants to delete their input, they can't delete the first character. Is there any way to inject it into the console instead?

I know this thing is built with dark magic and it has inherrent corruption but I have been on this quest for weeks and this is the best solution I have come up with so far. All suggestions for improvement would be greatly appreciated.

In reply to Non Blocking input on Win32 platforms by MisterH

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found