in reply to Re: Grabbing input - every char, not after <Enter>
in thread Grabbing input - every char, not after <Enter>

I was told to look at 'Term::ReadKey' but the sample code in perldoc just does the same thing as 'while(<>)' would. does anyone have a reference web page that shows how to grab every key, or give me an example loop? thanks
  • Comment on Re^2: Grabbing input - every char, not after <Enter>

Replies are listed 'Best First'.
Re^3: Grabbing input - every char, not after <Enter>
by Joost (Canon) on Sep 17, 2007 at 21:28 UTC
    It works for me:
    use Term::ReadKey; ReadMode 4; # Turn off controls keys while (not defined ($key = ReadKey(-1))) { # No key yet select undef,undef,undef,0.1; # sleep 0.1 secon +d } print "Get key $key\n"; ReadMode 0; # Reset tty mode before exiting
    run that:
    $ perl test.pl <press d> Get key d $
    update: the while() look does take up a tremendous amount of CPU time, though, so I added the select() call

      im an idiot, was looking at Term::ReadLine... thanks