Truman has asked for the wisdom of the Perl Monks concerning the following question:

Dear Fellow Monks,

I need to take input from the user (on the terminal window of a Win32 machine) and based on the occurrence of one particular character, I have to operate on the already entered text (before the occurrence of the character). For that, every single keystroke will need to be monitored.

I used Term::ReadKey with success, but what bothers me is that I have to use it constantly in a "while" loop(to monitor the keystrokes) -- and when that happens the CPU usage is almost 100 percent. I do not think that is desirable.

Is there any other way?

Replies are listed 'Best First'.
Re: Reading keys
by marto (Cardinal) on Oct 16, 2005 at 11:57 UTC
Re: Reading keys
by TedPride (Priest) on Oct 17, 2005 at 04:05 UTC
    I've sometimes wondered about this myself. If you can get input from <STDIN> and end it with a carriage return, why can't you set a different key to end the input? Why isn't there a way to get a single keystroke? getc() will return a character from the input stream, but it still waits for the carriage return, and setting the record separator to something other than \n doesn't work either.