From:	MERC::"uunet!WKUVX1.BITNET!MacroMan" 14-JUL-1992 04:07:53.53
To:	MACRO32@WKUVX1.BITNET, black@csulb.edu
CC:	
Subj:	Re: vax c unbuffered input

> I am trying to perform unbuffered input using VAX-C under VAX/VMS.
> I would like to read a single keyboard character without waiting
> for the RETURN key.  If possible, I would prefer a smarter read
> that can detect control keys such as the arrow-keys or the
> application keypad.  I have tried using the standard unixio
> functions read and getc, but these are buffered.  I will be incorporating
> the read requests into a program using VAX curses library.

You can use SYS$QIOW calls to read single characters (and arrow-keys
is just a sequence of characters). I have not used VMS curses, so the
only thing I know about it, is that it has a bad reputation.

If you want to start using SYS$QIOW, then you can take a look at the
following small program:

/* start of special IO module */

#include <string.h>
#include <descrip.h>
#include <iodef.h>

int sys$assign();
int sys$qiow();
int sys$dassgn();

short chan;

void ttopen()
{
   $DESCRIPTOR(ttdesc,"TT:");
   sys$assign(&ttdesc,&chan,0,0);
   return;
};

void putch(char k)
{
   sys$qiow(0,chan,IO$_WRITEVBLK,0,0,0,&k,1,0,0,0,0);
   return;
};

int kbhit()
{
   short charac[4];
   sys$qiow(0,chan,IO$_SENSEMODE|IO$M_TYPEAHDCNT,0,0,0,&charac,8,0,0,0,0);
   if (charac[0]>0)
      return 1;
   else
      return 0;
};

int getch()
{
   int k = 0;
   sys$qiow(0,chan,IO$_READVBLK|IO$M_NOECHO,0,0,0,&k,1,0,0,0,0);
   return k;
};

void ttclose()
{
   putch('\r');
   sys$dassgn(chan);
   return;
};

/* end of special IO module */

#include <stdio.h>
#include <ssdef.h>

int lib$wait();

main(int argc,char *argv[])
{
   int i;
   float t;
   char k;
   char pmt[]="Enter 1,2 or 3 ? ";
   ttopen();
   for (i=0;i<strlen(pmt);i++) {
      putch(pmt[i]);
   };
   t = 1.0;
   do {
      putch('.');
      lib$wait(&t);
   } while (!kbhit());
   k=getch();
   ttclose();
   printf("You entered : %c\n",k);
   return SS$_NORMAL;
};

Hope it helps !

                                                          Arne Vajhxj

Arne Vajhxj                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE
Business School of Southern Denmark     Internet:      ARNE@KO.HHS.DK

