Ace128:

I had a little fun playing with your program. I don't know if I solved the problem you're having or not. (Mostly because I was having so much fun, I forgot what the problem was while playing around.) The original version had a few quirks, but this one works better on my machine. Please give it a try and let me know what you think...

#!/usr/bin/perl -w use strict; use warnings; use Term::ReadKey; startListening(); sub startListening { ReadMode(4); # RAW mode (we'll do all the work!) my $echofl=1; # 1=Normal, 0=Password mode my $echoPwChar='#'; # Password mode char my $word = ''; # Input accumulator my $prompt = "> "; print $prompt; while (1) { my $char = ReadKey(0); my $ord = ord($char); if ($ord == 3) { # "\003" (^C) : STOP! print "\n^C -- terminated!\n"; last; } elsif ($ord == 10 or $ord == 13) { # "\n" (^J), "\r" (^M) : Finish line enterPressed($word); $word = ""; print $prompt; } elsif ($ord == 5) { # "\005" (^E) : Toggle echo mode $echofl = 1-$echofl; } elsif ($ord==127 or $ord==8) { # "\177" (DEL), "\010" (^H) : Kill last char print chr(8),' ',chr(8) if length($word)>0; chop($word); } elsif ($ord == 27) { # "\033" (Esc) : Clear line print chr(8) x length($word) . ' ' x length($word) . "\r" . $prompt; $word=""; } else { #if ($ord != 0) { # Otherwise add to word & update display $word .= $char; $char = $echoPwChar if !$echofl; print $char; } } ReadMode(0); } sub enterPressed { my $word = shift; print "\n '" . $word . "'\n"; }
--roboticus

In reply to Re: Term::ReadKey problem! by roboticus
in thread Term::ReadKey problem! by Ace128

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.