Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm sure I'm doing something silly OR maybe it's my terminal emulator, though I'm using standard putty. I'm real stumped and am hoping someone can spot my problem... The attached piece of code simply uses ReadKey to do single char I/O and echo its binary character value.

When there's input, I print ">>> GOT INPUT". Then I read it and print its value. If I type 8900098 the following is what I see:


root@poker collectl# ./sht.pl
>>> GOT INPUT
INPUT: 56
>>> GOT INPUT
INPUT: 57
>>> GOT INPUT
>>> GOT INPUT
>>> GOT INPUT
>>> GOT INPUT
INPUT: 57
>>> GOT INPUT
INPUT: 56

so what happened to the echos of the '0's? Here's the code that does it:

#!/usr/bin/perl -w use Term::ReadKey; use IO::Select; ReadMode 4; my $sel=new IO::Select(STDIN); my $ctrlCFlag=0; while (!$ctrlCFlag) { while(my @ready = $sel->can_read(1)) { foreach my $filehandle (@ready) { if ($filehandle eq 'STDIN') { print ">>> GOT INPUT\n"; while (my $char=ReadKey -1) { my $byte=unpack('C', $char); printf "INPUT: %d\n", $byte; if ($byte==3) { $ctrlCFlag=1; last; } } } } } } ReadMode 0;

can_read() says there's something to be read on STDIN but ReadKey isn't see anything. And what's so special about '0'? Isn't it just another key? Any and all help will be greatly appreciated. -mark


In reply to ReadKey can't see 0 key... by markseger

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 meditating upon the Monastery: (6)
As of 2024-04-24 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found