Intercepting "Enter" key

Intercepting "Enter" key

am 10.01.2008 15:36:20 von apogeusistemas

Hi:
How could I intercept "enter" key using a case statement?

Thank you.

Re: Intercepting "Enter" key

am 10.01.2008 15:51:49 von Ed Morton

apogeusistemas@gmail.com wrote:
> Hi:
> How could I intercept "enter" key using a case statement?
>
> Thank you.


That could mean just about anything. Prtovide some more details
including sample input and expected output.

Ed.

Re: Intercepting "Enter" key

am 10.01.2008 19:01:53 von cfajohnson

On 2008-01-10, apogeusistemas@gmail.com wrote:
>
> How could I intercept "enter" key using a case statement?


LF=$( printf "\n" )
CR=$( printf "\r" )

case $KEY in
"$LF") echo Line feed entered ;;
"$CR") echo Carriage return entered ;;
esac

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Re: Intercepting "Enter" key

am 10.01.2008 19:12:31 von Edward Rosten

On Jan 10, 7:36 am, apogeusiste...@gmail.com wrote:
> Hi:
> How could I intercept "enter" key using a case statement?

What do you mean? Can you provide a code example of what you currently
have?

-Ed
--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r
230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}for/s 12 d f
pop 235 420 translate 0 0 moveto 1 2 scale show showpage

Re: Intercepting "Enter" key

am 10.01.2008 19:51:54 von Stephane CHAZELAS

On Thu, 10 Jan 2008 13:01:53 -0500, Chris F.A. Johnson wrote:
> On 2008-01-10, apogeusistemas@gmail.com wrote:
>>
>> How could I intercept "enter" key using a case statement?
>
>
> LF=$( printf "\n" )

That won't work. Command substitution removes all the trailing LFs.

LF='
'

or:

eval "$(printf 'LF="\n"')"

or:

LF=$(printf '\n.'); LF=${LF%.}

....

--
Stephane

Re: Intercepting "Enter" key

am 11.01.2008 04:26:10 von Barry Margolin

In article
,
apogeusistemas@gmail.com wrote:

> Hi:
> How could I intercept "enter" key using a case statement?
>
> Thank you.

Do you mean you want to detect when the user has typed an empty response
to a question?

read response
if [ -z "$response" ]
then echo Please type something
else echo "You typed '$response'"
fi

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: Intercepting "Enter" key

am 12.01.2008 22:16:32 von brian_hiles

apogeusiste...@gmail.com wrote:
> How could I intercept "enter" key using a case statement?

A general method from the Kornshell FAQ at
http://kornshell.com/doc/faq.html :

Q4. How can a write a ksh script that responds directly to each
character so that you user just has to enter y, not y?
A4. There are two ways to do this. The easiest is to use:

read -n1 x

Alternatively, you could do:

function keytrap
{
.sh.edchar=${sh.edchar}$'\n'
}
trap keytrap KEYBD

and then:

read x

=Brian