Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Reading the Putty Window Title (or how can I read from STDIN with out having to hit the [Enter] key?

by NateTut (Deacon)
on Sep 04, 2009 at 18:23 UTC ( #793537=perlquestion: print w/ replies, xml ) Need Help??
NateTut has asked for the wisdom of the Perl Monks concerning the following question:

This question is a follow on to: How to Get XTerm Title

I can read the window title Putty is sending only after doing a Enter from the keyboard. Do I need to do a non-blocking read from the keyboard? Is there a way I can send a "\n" to STDIN?
#!/usr/bin/perl use strict; use warnings; $| = 1; # # Main # my $SaveSTDIN; print "\033[21t;"; my $Response = <STDIN>; open(STDIN, "<&$SaveSTDIN"); print("\$Response\[$Response\]\n"); my @Characters = split(//, $Response); foreach my $Character (@Characters) { print("\[$Character\]\[" . (ord($Character)) . "\]\n"); }

Comment on Reading the Putty Window Title (or how can I read from STDIN with out having to hit the [Enter] key?
Select or Download Code
Re: Reading the Putty Window Title (or how can I read from STDIN with out having to hit the [Enter] key?
by almut (Canon) on Sep 04, 2009 at 18:48 UTC

    The problem is that input is normally line buffered, but you could use Term::ReadKey.  Something like

    #!/usr/bin/perl use strict; use warnings; use Term::ReadKey; $| = 1; print "\e[21t"; ReadMode 3; my $key; while (not defined ($key = ReadKey(-1))) { } while (defined ($key = ReadKey(-1))) { print "key: $key\n"; } ReadMode 0; __END__ key: ] key: L key: T key: e key: r key: m key: i key: n key: a key: l key:  key: \
      Excellent. Thank you!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://793537]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-07-22 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (110 votes), past polls