If you only want to capture keystrokes at a particular time, try adapt the following...
Code:
#!/bin/ksh
echo "Enter password:\c "
char=""; password="";
terminalSettings=$(stty -g)
stty -echo raw # turn off terminal output & canonical mode
return=$(print -n "\r")
while ! ${returnDetected-false}
do
password=${password}${char}
char=$(dd bs=1 count=1 2> /dev/null)
if [ "${char}" != "${return}" ]
then
print -n "*"
else
returnDetected=true
fi
done
stty ${terminalSettings} # restore stty settings
echo "\nPassword entered: ${password}"