From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM" 11-APR-1994 09:17:03.35
To:	EVERHART
CC:	
Subj:	Re: Dbase IV "inkey" implementaion for the VAX?

Date: Tue, 05 Apr 1994 11:59:16 +0100
From: Arne Vajhoej <ARNE@kopc.hhs.dk>
Subject: Re: Dbase IV "inkey" implementaion for the VAX?
To: ian@MARS.SENECAC.ON.CA, INFO-VAX@SRI.COM
Message-Id: <01HATCD4SEXE8WW1AQ@kopc.hhs.dk>
X-Vms-To: KOPC::IN%"ian@MARS.SENECAC.ON.CA"
X-Vms-Cc: IN::"INFO-VAX@SRI.COM"
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-1
Content-Transfer-Encoding: 8BIT

> I need to have a program:
> 
>         a) display some menu
>         b) refresh the time at the corner of the screen
>         c) accept a menu selection as an intger
> 
> I have (a) and (b) working on a VAX using the C language.
> 
> My question is:
> 
>  On VMS, how does one refresh the time in an infinite loop ("b" above) as well
>  as check the keyboard buffer for input ("c" above) concurrently?
>  (Something like "inkey" in dbase 4)

I have posted the program attached below rather frequently. It show how to:
  - read a single key without return
  - test if a key has been pressed
  - catch CTRL/Y

I believe it will answer some of your questions.

                                                          Arne

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

================================================================================

/* start of special IO module */

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

#define TRUE 1
#define FALSE 0

long sys$assign();
long sys$qiow();
long sys$dassgn();
long lib$disable_ctrl();
long lib$enable_ctrl();

short chan;
long ctrlint = FALSE;

void catcher()
{
   ctrlint = TRUE;
   return;
}

void ttopen()
{
   $DESCRIPTOR(ttdesc,"TT:");
   long mask;
   sys$assign(&ttdesc,&chan,0,0);
   mask = LIB$M_CLI_CTRLY;
   lib$disable_ctrl(&mask);
   sys$qiow(0,chan,IO$_SETMODE|IO$M_CTRLYAST,0,0,0,catcher,0,0,0,0,0);
   return;
}

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

void putstr(char *s)
{
   sys$qiow(0,chan,IO$_WRITEVBLK,0,0,0,s,strlen(s),0,0,0,0);
   return;
}

long 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 TRUE;
   else
      return FALSE;
}

long ctrlychit()
{
   return ctrlint;
}

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

void ttclose()
{
   long mask;
   putch('\r');
   mask = LIB$M_CLI_CTRLY;
   lib$enable_ctrl(&mask);
   sys$dassgn(chan);
   return;
}

/* end of special IO module */

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

long lib$wait();

main(long argc,char *argv[])
{
   long i;
   float t;
   char k;
   char pmt[]="Enter 1,2 or 3 ? ";
   ttopen();
   putstr(pmt);
   t = 1.0;
   do {
      putch('.');
      lib$wait(&t);
   } while (!(kbhit()||ctrlychit()));
   if (ctrlychit()) {
      ttclose();
      printf("Interrupted by user !\n");
   } else {
      k=getch();
      ttclose();
      printf("You entered : %c\n",k);
   };
   return SS$_NORMAL;
}

