LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   take esc key as input (https://www.linuxquestions.org/questions/linux-software-2/take-esc-key-as-input-816112/)

csegau 06-24-2010 07:11 AM

take esc key as input
 
hi,

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";;
esac

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'.
Code:

#!/bin/bash
echo "Please hit escape:"
read -s -n1 variable

case $variable in

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

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

esac

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


All times are GMT -5. The time now is 09:15 AM.