From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 15-MAR-1991 08:49:05.00
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.91)
	 id AA17811; Fri, 15 Mar 91 08:30:44 EST
Received: From UCBVAX.BERKELEY.EDU by CRVAX.SRI.COM with TCP; Thu, 14 MAR 91 13:13:38 PST
Received: by ucbvax.Berkeley.EDU (5.63/1.42)
	id AA14134; Thu, 14 Mar 91 13:09:01 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 13 Mar 91 14:52:59 GMT
From: sdd.hp.com!spool.mu.edu!vmsd.csd.mu.edu!8099PIERZINA@decwrl.dec.com  (Todd Pierzina)
Organization: Marquette University - Computer Services
Subject: Re: emulating kbhit in VMS
Message-Id: <009458A1.A269D1C0@vmsd.csd.mu.edu>
References: <9103091327.AA17089@ucbvax.Berkeley.EDU>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <9103091327.AA17089@ucbvax.Berkeley.EDU>, ERHART@CISCO.NOSC.MIL writes:
>     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.  

I'm sure this has already been answered, but I have a pretty neat solution to
this problem.  It checks to see if any keys are in the type-ahead buffer, and
returns a 1 in R0 (true) if so.  It doesn't read the key, it leaves it in the
buffer, so you can read the key if you want to see what was pressed.

From FORTRAN:

    integer*2 Chan
    integer TYPAHDCNT	!logical will work also
    ...
    call SYS$ASSIGN ('TT:', Chan)
    ...
    if (TYPAHDCNT(Chan) .eq. 1) then
    ...
    end if

-------------------------- Cut Here ---------------------------------------

	.TITLE	GETTYAHD - get the terminal type ahead count
	.LIBRARY /SYS$LIBRARY:LIB.MLB/
;
; You must pass an integer word channel as an argument to this routine.
; This routine will return an integer value telling the user whether
; there are any characters in the typeahead buffer. The returned value
; will be as follows:
;
;	0 - no character in typeahead buffer
;	1 - some characters in typeahead buffer
;
CHARS:	.BLKQ	1
CHAN:	.BLKW	1
	.ENTRY	TYPAHDCNT,0
	MOVW	@4(AP),CHAN
	$QIOW_S	CHAN=CHAN,FUNC=#IO$_SENSEMODE!IO$M_TYPEAHDCNT,P1=CHARS
	CMPL	R0,#SS$_NORMAL
	BNEQU	ZERO
	TSTW	CHARS
	BEQL	ZERO
	MOVL	#1,R0
	RET
ZERO:	CLRL	R0
	RET
	.END

Todd Pierzina

Student Programmer
Marquette University
8099PIER@MUCSD                (BITNET)
8099pierzina@vmsd.csd.mu.edu  (Internet)

