LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 06-24-2010, 07:11 AM   #1
csegau
LQ Newbie
 
Registered: Oct 2009
Posts: 27

Rep: Reputation: 0
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
 
Old 06-24-2010, 07:59 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remap Caps Lock key to ESC MTK358 Linux - Newbie 6 06-03-2010 03:52 PM
[SOLVED] BASH --> esc key in a case statement manwithaplan Linux - Newbie 6 10-05-2009 10:33 PM
Changing the Meta key from Esc to Alt primo *BSD 0 08-27-2005 05:18 PM
Mapping Esc to windows key in Vim frankie_DJ Linux - Newbie 2 10-14-2004 02:56 PM
Damn 'Esc' key crabboy General 1 05-15-2001 10:05 PM


All times are GMT -5. The time now is 12:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration