Subject: | Workaround to not to have to press "enter" twice for ReadKey() under Windows |
If you do the following thing under Windows:
use Term::ReadKey;
ReadMode 3; # or 4, or 5
ReadKey 0;
ReadMode 0;
This will wait for you to press one normal key, before continuing... except for the "enter" key, which you have to press twice. It works normally (= as any other key) on Linux.
I guessed that this might be related to the CR+LF -> LF foo on Windows, so I tried to use binmode():
use Term::ReadKey;
binmode STDIN;
ReadMode 3; # or 4, or 5
ReadKey 0;
ReadMode 0;
and lo! It works! So I likely must have guessed right.
IMO this either should be documented in the docs, or maybe a (transparent) workaround be coded in the module.
n.b. ReadKey() returns chr(13) ("\r") for <enter>. That might be patched, too, as Perl on Windows prefers "\n".