QB SIMULATNEOUS INPUT

 BBS: Inland Empire Archive
Date: 11-21-92 (19:52)             Number: 361
From: BRENT ASHLEY                 Refer#: NONE
  To: RAYMOND PAQUIN                Recvd: NO  
Subj: QB SIMULATNEOUS INPUT          Conf: (2) Quik_Bas
-> The question was not 'how do you capture TWO key presses' but 'how do
-> you capture THREE keypresses' when two of those three keys are 'real'

The following answer will clarify that all that can be done and more.
Remember that at the INT 9 level, all keys are just scan codes, state
keys (ctl/alt/shft) and otherwise (abc...).

I've written a short assembly routine which will allow detection
of multiple keypresses.  It works by hooking the INT 9 BIOS
keyboard handler and maintaining its own local array of flags
representing the pressed status of each available scancode.

The syntax of this beast is as follows:

DECLARE FUNCTION KeyPressed%(ScanCode%)

'install our keyboard monitor
CALL InstKeyPress

'your code
.
.
.
IF KeyPressed(ScanCode1%) AND KeyPressed(ScanCode2%) THEN
  CALL BothOfThoseKeysWerePressed
ENDIF
.
.
.
'remove monitor before exit or lockups will occur - a good idea is
'to ON ERROR GOTO some code which unhooks it in case there is an
'unexpected program termination.
CALL UnhookKeyPress

Here's an example program:

-------------------8<-- cut here -->8------------------------

' KP.BAS by Brent Ashley
'
' demonstrates the use of KeyPress routine
' to monitor the status of multiple keys

DEFINT A-Z
DECLARE SUB InstKeyPress()
DECLARE SUB UnhookKeyPress()
DECLARE FUNCTION KeyPressed(ScanCode%)

InstKeyPress
CLS: PRINT "Press keys 1-8, <ESC> to quit"
DO
  LOCATE 2,1
  FOR i = 2 to 9 ' scan codes for 1 to 8
    IF KeyPressed(i) THEN PRINT CHR$(47 + i); ELSE PRINT ".";
  NEXT
LOOP UNTIL INKEY$=CHR$(27)
UnhookKeyPress
END

-------------------8<-- cut here -->8------------------------

The following message contains the ASM code for this assembly
module.  You'll need MASM 5.1 or greater to create the OBJ file (I
used QC/QuickAssembler v2.51).  Those who want the OBJ for this
will have to get it from RelayNet or NorthAmeriNet, where reason
prevails and PostIt is allowed for such things.

-----
Brent
-----
--- FidoPCB v1.3 [ff053/x]
 * Origin: Canada Remote Systems, Mississauga, Ontario  (1:229/15)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET