Hi guys, I've found two nifty little scripts on these forums one which detects if the F5 key has been pressed:
#/bin/sh
_key()
{
local kp
ESC=$'\e'
_KEY=
read -d '' -sn1 _KEY
case $_KEY in
"$ESC")
while read -d '' -sn1 -t1 kp
do
_KEY=$_KEY$kp
case $kp in
[a-zA-NP-Z~]) break;;
esac
done
;;
esac
printf -v "${1:-_KEY}" "%s" "$_KEY"
}
_key x
case $x in
$'\e[15~') echo You have pressed F5 ;;
esac
and one which does a countdown:
#/bin/sh
countdown=10
while [[ ${countdown} -ge 0 ]]
do
#echo ${countdown}
echo "${countdown} second(s) left"
sleep 1
countdown=$(( ${countdown} - 1 ))
done
What I'm trying to do is join these scripts together so that when my script runs, it does a countdown to 0 - once it gets to zero it calls a 'default' function I've written which uses non user specified parameter, but what I'd like is the user to be able to hit the F5 key if they like and 'stop' the countdown process - this will then call another function I've written which allows the user to input their own parameters. I can't seem to 'weld' the two scripts together however all attempts have failed mostly because I don't understand entirely how the key press script works? Does anyone see how I could do this? Cheers.
---------- Post updated at 07:38 PM ---------- Previous update was at 03:28 PM ----------
Does no one have any idea how to achive this
countdown=10
while [[ ${countdown} -ge 0 ]]
do
echo "Automatic search using today's date will begin in ${countdown} second(s)."
echo "Press F5 to cancel and specify another date."
sleep 1
countdown=$(( ${countdown} - 1 ))
if [[ $countdown == 0 ]]; then
# run the automatic search using today's date
# by calling the SearchAuto function
SearchAuto
fi
#more script needed here
#if key is pressed, cancel loop and call the manual search function
done