Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Capturing non-printable characters isn't that different from capturing any other character. One gotcha is that on a terminal your program usually does not receive any characters until the user hits the <ENTER> key.

If you want to capture individual characters, you need to check which characters have a meaning to your console - and thus never reach your program. The following small example uses Term::ReadKey in "raw" mode to capture one byte and then prints its hex value plus its interpretation. This works for the escape key and also for combinations with the <CTRL> key.

A warning, though: This example reads one byte, not one character. If your terminal uses UTF-8 encoding and you enter a key outside the ASCII range, then you'll receive only part of one character (Dealing with UTF-8 is left as an exercise to the reader). Also, cursor keys, function keys and the like are usually sequences which start with an escape character, my short example drops the rest of the sequence.

use Term::ReadKey; use charnames ':full'; ReadMode 4; print "Enter a key: "; my $key = ReadKey(0); printf "%v02x",$key; print " = ",charnames::viacode(ord $key),"\n"; END { ReadMode 0; }

In reply to Re: Capture a non-printable char and test what it is by haj
in thread Capture a non-printable char and test what it is by almsdealer

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: (4)
As of 2024-04-26 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found