http://qs321.pair.com?node_id=316644

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

Hi guys!

I have a function that prints to console the line Please press any key to continue and waits for a keyboard key to be presses, it was working for ages. I'v just noticed that it doesn't work anymore, it gets stuck in the middle and no matter what key I press, the program doesn't continue on the console. Here it is:
use Term::ReadKey; sub pressAnyKey { print "Press any key to continue...\n\n"; ReadMode 4; # turn off control keys While (not defined ($key = ReadKey(-1))) {} readMode 0; # restore read mode }
If I remember right this function was suggested by another monk, a long time ago when I needed an advice on the matter, and it worked perfectly since than. It seems that the function get stuck on the while loop, as if no key press breaks out of it.
Anyone see something?

Title edit by tye/small>

Replies are listed 'Best First'.
Re: Term::ReadKey
by Thelonius (Priest) on Dec 23, 2003 at 17:45 UTC
    I would try re-installing Term::ReadKey. Also, instead of looping with ReadKey(-1), you could try just calling ReadKey(0) once.

    You could also check $! to see if getc returned an unexpected error. Note, however, that $! is not reset to 0 automatically, so you should clear it out beforehand, and that some errors would be expected--what error you would normally get when no character is available may differ by operating system.

Re: Term::ReadKey
by xenchu (Friar) on Dec 23, 2003 at 22:03 UTC

    Try what Thelonius advised, but the real answer to your question is "What changed?". If something worked for a long time and then it doesn't work anymore, then something isn't what it used to be. What Thelonius suggested will probably fix the immediate problem but if you really want to know what happened (and perhaps prevent future problems), do the research and find out.

    xenchu


    The Needs of the World and my Talents run parallel to infinity.