#!/usr/bin/perl -w
######################################################################
# readkey.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

use Term::ReadKey;                      # include module
$| = 1;                                 # debuffer output

######################################################################
# 'Blind' input
######################################################################
ReadMode('noecho');                     # activate 'blind input'
print "Enter password: ";               # input prompt
$pass = ReadLine(0);                    # normal line input
chop($pass);                            # cut off newline
print "Password: '$pass'\n";            # output for testing
ReadMode('normal');                     # reset terminal

######################################################################
# Input of individual characters
######################################################################
$timeout = 5;                           # timeout after 5 seconds

print "Input character, terminate with 'q': \n";
ReadMode('raw');                        # block control characters

while(1) {                              # endless loop
    while (!defined ($key = ReadKey($timeout))) {
        print "Hi there, wake up!\n";   # no input yet
    }
    print "Entered: '$key'\n";
    last if $key eq "q";                # terminate or repeat
}

ReadMode('normal');                     # reset terminal mode

