Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Term::ReadKey locks up?

by hotshot (Prior)
on Dec 23, 2003 at 16:15 UTC ( #316644=perlquestion: print w/ replies, xml ) Need Help??
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>

Comment on Term::ReadKey locks up?
Download Code
Re: Term::ReadKey
by Thelonius (Curate) 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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2014-10-02 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (48 votes), past polls