Firstly, Term::Readkey is a pretty small module so it's no great overhead to install and use it and it seemed to do everything right whenever I used it. My advice would be to go with that.

However, if you are unable to do that you probably have to go with changing terminal settings by hand. I copied a recipe out of the 2nd edition Camel Book a long, long time ago and I haven't used it in years. It may give you a start though so here it is.

# RawTerm.pm # # Adapted from "Programming PERL", Wall/Christiansen/Schwartz, 2nd Edn +. pp.474 # package RawTerm; use Exporter; @ISA = ('Exporter'); @EXPORT = ('getone'); BEGIN { use POSIX qw(:termios_h); my($term, $oterm, $echo, $noecho, $fd_stdin); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new(); $term->getattr($fd_stdin); $oterm = $term->getlflag(); $echo = ECHO | ECHOK | ICANON; $noecho = $oterm & ~$echo; sub cbreak { $term->setlflag($noecho); $term->setcc(VTIME, 1); $term->setattr($fd_stdin, TCSANOW); } sub cooked { $term->setlflag($oterm); $term->setcc(VTIME, 0); $term->setattr($fd_stdin, TCSANOW); } sub getone { my $key = ""; cbreak(); sysread(STDIN, $key, 1); cooked(); return $key; } } END { cooked(); } 1;

If I remember correctly you just call the getone() subroutine to get a single character without needing the <Enter> key. I hope this is of use.

Cheers,

JohnGG


In reply to Re: y/n input in a captive interface by johngg
in thread y/n input in a captive interface by apotheon

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.