How do I detect a keyboard press?
Daniel Smith "innovation, not litigation..."
daniel at island.COM
Tue May 7 07:13:46 AEST 1991
In <1991May3.070038.3659 at swsrv1.cirr.com> toma at swsrv1.cirr.com (Tom Armistead) writes:
> In article <1991May2.125554.11557 at vaxa.strath.ac.uk> cadp35 at vaxa.strath.ac.uk writes:
> >any of you wiz's know how I can detect a keyboard press in shell script??
> >
> >I want it for a script which will execute a certain option if I press the
> >correct key.
One way is to get my grabchars package from comp.sources.misc archives,
which was written to do just this. You can also get it directly from
me. I also include scripts which can generate skeletons of menuing
scripts.
Another thing you can do is this:
(reassemble this as one line...)
alias get_choice 'set choice_prompt=(\!*); echo -n "$choice_prompt"; s
tty cbreak ; set choice=`echo "dd if=/dev/tty bs=1 count=1 2>/dev/null"|sh|cat -
v` ; stty -cbreak'
as in:
get_choice ' your choice >> '
if ("$choice" =~ '?') set choice=help
if ("$choice" =~ '^[') set choice=escape
switch ($choice)
bla bla bla...
endsw
Daniel
--
daniel at island.com Daniel Smith, Island Graphics, (415) 491 0765 x 250(w)
daniel at world.std.com 4000 CivicCenterDrive SanRafael MarinCounty CA 94903
dansmith at well.sf.ca.us Fax: 491 0402 Disclaimer: Hey, I wrote it, not IG!
falling/yes I'm falling/and she keeps calling/me back again - IJSaF, Beatles
More information about the Comp.unix.questions
mailing list