Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!island!daniel From: daniel@island.COM (Daniel Smith "innovation, not litigation...") Newsgroups: comp.unix.questions Subject: Re: How do I detect a keyboard press? Keywords: Like this. Message-ID: <4007@island.COM> Date: 6 May 91 21:13:46 GMT References: <1991May2.125554.11557@vaxa.strath.ac.uk> <1991May3.070038.3659@swsrv1.cirr.com> Organization: Island Graphics, Marin County, California Lines: 40 In <1991May3.070038.3659@swsrv1.cirr.com> toma@swsrv1.cirr.com (Tom Armistead) writes: > In article <1991May2.125554.11557@vaxa.strath.ac.uk> cadp35@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@island.com Daniel Smith, Island Graphics, (415) 491 0765 x 250(w) daniel@world.std.com 4000 CivicCenterDrive SanRafael MarinCounty CA 94903 dansmith@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