From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 10-MAR-1991 10:26:05.28
To:	ARISIA::EVERHART
CC:	
Subj:	Re: emulating kbhit in VMS

From:	RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP@CRDGW2
To:	Everhart@Arisia@MRGATE

Received:  by crdgw1.ge.com (5.57/GE 1.89)
	 id AA28385; Sun, 10 Mar 91 09:47:24 EST
Received: From DANPOST.UNI-C.DK by CRVAX.SRI.COM with TCP; Sun, 10 MAR 91 06:35:23 PST
Received: from vms2.uni-c.dk by danpost.uni-c.dk (5.65/4.7)
	id AA14916; Sun, 10 Mar 91 14:33:29 GMT
Date: Sun, 10 Mar 91 15:36 +0100
From: ISIS08@ecostat.aau.dk
Subject: Re: emulating kbhit in VMS
To: ERHART@CISCO.NOSC.MIL, INFO-VAX@SRI.COM
Message-Id: <A989CFD3F31F030EDD@vms2.uni-c.dk>
X-Envelope-To: ERHART@CISCO.NOSC.MIL, INFO-VAX@SRI.COM
X-Vms-To: UNIL63::IN%"ERHART@CISCO.NOSC.MIL"
X-Vms-Cc: IN::"INFO-VAX@SRI.COM"

>      I've got a question, (last time I asked about SMG),  I've built a
> program using   SMG$CREATE_VIRTUAL_KEYBOARD  and SMG$READ_COMPOSED_LINE
> to use VMS's recall buffer.  I got what I wanted from DEC (Colorado)
> and I revised and tested and finally got it to work.
>      Now the question I have is about a C routine available in Micro-Soft) C
> called    kbhit    which allows you to interupt processing by typing any
> key on the keyboard, I need this on the VAX, I can't seem to get
>                          SMG$READ_KEYSTROKE
> to work under these conditions.  For example I'm reading in records
> from a file, processing them, taking data from them and then I want to
> stop - only not every time - in the middle of that to look at my screen,
> I hit any key and the processing stops, I look at my screen, press any
> key when I'm done looking and the read resumes where I left off.  If I
> don't press any key it reads all through the file.

You can use asynchronous IO to emulate the kbhit()-function. The
following small program illustrates the technique.

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

#define FALSE 0
#define TRUE 1

int hit = FALSE;
int first = TRUE;

int sys$assign();
int sys$qio();

int sethit()
{
   hit = TRUE;
   return SS$_NORMAL;
};

int kbhit()
{
   int stat,chan,k;
   $DESCRIPTOR(term,"TT");
   if (first) {
      stat = sys$assign(&term,&chan,0,0);
      stat = sys$qio(0,chan,IO$_READVBLK|IO$M_NOECHO,0,sethit,0,&k,1,0,0,0,0);
      first = FALSE;
   };
   return hit;
};

main(int argc,char *argv[])
{
   int i;
   i = 0;
   while (!kbhit()) {
      i++;
      printf("%d\n",i);
   };
   return SS$_NORMAL;
};

It should be rather easy to expand this program to suit your needs.

                                                                 Arne

Arne Vajhxj                             Internet: ISIS08@ECOSTAT.AAU.DK
Institute of Economics and Statistics   PSI:      DATAPAX.23830211371400::ISIS08
Aarhus University
Denmark


