🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #598

Re: How to test for a key ALREADY pressed?

#598
From: aki
Date: Tue, 07 Apr 1992 18:04
31 lines
1514 bytes
In article <rqjbpINNiqv@matt.ksu.ksu.edu>, kentiler@matt.ksu.ksu.edu (Kent Iler) writes:
> Hello,
>    Is there a way to test to see if a key is already pressed.  Let say I run
> this program from the autoexec, and I want to see if the space bar is pressed.
> If it is I want to do one thing, if not I want to do another.  I don't want to
> wait there for a key to be pressed, just see if it already is.  I have C++ and
> Turbo Pascal to program with.  Thanks.
> 						--Kent


Try this:

  if (bioskey(1)==0) /* No key pressed */
  else /* key pressed */

  bioskey is defined in bios.h,  but here is a generic version of it:

  int bioskey(int cmd)
  {
    struct REGPACK rp;
    rp.r_ax=cmd<<8;
    intr (0x16, &rp);
    if ( ((rp.r_flags&0x40)==0x40) && (cmd==1) )
      return 0; /* ZF set if no key pressed, return 0 */
    return rp.r_ax; /* else AH=Scan Code, AL=ASCII Char */
  }

Aki.
-- 
/  Phone: 408-662 9664 Fax: 662 9676  |  "Aki" pronounced: Ah-Key. I know  \ 
\  GENIE: A.KORHONEN  Home: /dev/nul  |  what I'm doing most of the time.  /
Technical Details
Message-ID: <3519@cruzio.santa-cruz.ca.us>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcomsv!cruzio!aki
References: <rqjbpINNiqv@matt.ksu.ksu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcomsv!cruzio!aki
From: aki@cruzio.santa-cruz.ca.us
Newsgroups: comp.os.msdos.programmer
Subject: Re: How to test for a key ALREADY pressed?
Message-ID: <3519@cruzio.santa-cruz.ca.us>
Date: 7 Apr 92 18:04:11 GMT
Article-I.D.: cruzio.3519
References: <rqjbpINNiqv@matt.ksu.ksu.edu>
Sender: aki@cruzio.santa-cruz.ca.us
Reply-To: aki@cruzio.santa-cruz.ca.us
Lines: 31