在 Linux 底下可以真的顯示 * 號,但windows要readmode 為2才可讓我能成功enter,不過是enter完後才看到*號
use Term::ReadKey;
my $key = 0;
my $password = “”;
print ”
Please input your password: “;
# Start reading the keys
#ReadMode(4); # Disable the control keys for linux
ReadMode(2); # for Windows
while(ord($key = ReadKey(0)) != 10)
# This will continue until the Enter key is pressed (decimal value of 10)
{
$password = $password.$key;
print “*”;
}
ReadMode(0); #Reset the terminal once we are done
print “Your super secret password is: $password
“;
# ref: http://zh-tw.w3support.net/index.php?db=so&id=701078
# ref: http://forums.devshed.com/perl-programming-6/problem-with-readmode-under-use-term-readkey-462494.html
留言