6 Answers
6

You can play with Term::ReadKey. Here is a very simple example, with some detection for backspace and delete key. I've tested it on Mac OS X 10.5 but according to the ReadKey manual it should work under Windows. The manual indicates that under Windows using non-blocking reads (ReadKey(-1)) will fail. That's why I'm using ReadKey(0) who's basically getc (more on getc in the libc manual).

This does not work under Windows. It works fine until you come to hit the enter key, when you have to press it four time for it to react. If you use ReadMode(2), then it works fine, but doesn't echo until you hit return. Not displaying the * may be an acceptable alternative
–
Matthew FarwellMar 31 '09 at 18:16

2

It does not work on Windows because the decimal ascii value of the Enter or Return key is 13 (CR: carriage return). Once you replace the line while(ord($key = ReadKey(0)) != 10) with while(ord($key = ReadKey(0)) != 13), it works better :)
–
DamienJun 20 '11 at 12:48