-   Linux - Software (
-   -   take esc key as input (

csegau 06-24-2010 07:11 AM

take esc key as input

I have to take "esc" key as input without hitting enter key

I am doing like this
read -s -n1 variable

Now,i have to use this value $variable to jump to particular case
in "switch"(case) construct.

i am unable to do it

case $key in
pattern) echo "escape key is pressed";;

what should be pattern? here.

thanks in advance

David the H. 06-24-2010 07:59 AM

You can enter a literal escape character with the sequence $'\e'.

echo "Please hit escape:"
read -s -n1 variable

case $variable in

    $'\e') echo "escape key pressed" ;;

    *) echo "that's not it" ;;


The bash man page section on quoting explains it in more detail.

All times are GMT -5. The time now is 09:57 PM.