[comp.lang.c] Keys

vvcns@mars.lerc.nasa.gov (Allen Holtz) (08/16/90)

     I was wondering if anybody knows how to make a program accept input
from the keyboard without the user pressing the return key.  For example,
if a user is asked a yes or no question and s/he types a y, the program
will continue as if return was pressed.  I am working on a VAX/VMS system
v5.1.  I would appreciate any help.

Thanks,

Allen

--------------------------------------------------------------------------------
Allen Holtz                   |  Phone: (216)433-6005
NASA Lewis Research Center    | 
--------------------------------------------------------------------------------
If you make people think they're thinking, they'll love you; but if you
really make them think, they'll hate you.
--------------------------------------------------------------------------------

catfood@NCoast.ORG (Mark W. Schumann) (08/17/90)

In article <1990Aug16.160043.20584@eagle.lerc.nasa.gov> vvcns@mars.lerc.nasa.gov writes:
>
>     I was wondering if anybody knows how to make a program accept input
>from the keyboard without the user pressing the return key.  For example,
>if a user is asked a yes or no question and s/he types a y, the program
>will continue as if return was pressed.  I am working on a VAX/VMS system
>v5.1.  I would appreciate any help.
>

Actually, this is not exactly a C question.  C thinks 'stdin' is
a stream of bytes, not a keyboard.  Some operating systems buffer
all keystrokes until <ENTER> or some such is struck, and on those
systems there is no way to do what you are asking.  (CPF/400 on
the IBM AS/400 is one notable example near and dear to my heart.)

On VMX 5.1, you can use getch() or one of the runtime library 
functions.  Try HELP Run-Time to get started.

Good luck!



-- 
============================================================
Mark W. Schumann  3111 Mapledale Avenue, Cleveland 44109 USA
Domain: catfood@ncoast.org
UseNet: ...usenet.ins.cwru.edu!ncoast!catfood
============================================================

ping@cubmol.bio.columbia.edu (Shiping Zhang) (08/17/90)

In article <1990Aug16.160043.20584@eagle.lerc.nasa.gov> vvcns@mars.lerc.nasa.gov writes:
 
>     I was wondering if anybody knows how to make a program accept input
>from the keyboard without the user pressing the return key.  For example,
>if a user is asked a yes or no question and s/he types a y, the program
>will continue as if return was pressed.  I am working on a VAX/VMS system
>v5.1.  I would appreciate any help.

Have you ever tried to use ioctl()?
This function can be used to set the terminal into the "raw" mode.
With this mode, characters are readable immediately.

-ping