Using the Keyboard Buffer
The BIOS has a default memory area for the keyboard buffer which holds up to 16 keystrokes.
This area starts at 0040:001Eh and is 32 bytes in length. (16 2-byte scancodes)
The word (2 bytes) at 0040:001Ah hold the current head of the BIOS keyboard buffer.
The word (2 bytes) at 0040:001Ch hold the current tail of the BIOS keyboard buffer.
If these two pointers are different, then there is a keystroke ready for extraction.
KEYBUFF.C (1,728 bytes) is a small example on how to get keystrokes from the keyboard buffer.
Version: 1.00
Author: Ben Lunt (Forever Young Software)
Date: 24 May 1998
Compiler: Quick C 2.5
Checking to see if a key is pressed with out the annoying keyboard delay.
From an email message:
> I'd like to know how to control the keyboard buffer in QuickBasic so
> that you don't have to wait a few secs for something to happen when you
> press and hold down a key.
> Like when you program action games in QB you want the thingie on the
> screen to start moving at once if you press and hold down let us say the
> SPACE-key, or an arrow-key.
When you press a key on the keyboard, the keyboard hardware sends a 'make' code to the interrupt. Then when you release this key, the hardware sends a 'break' code.
In most cases, the software interrupt grabs the first 'make' code and then ignores the rest for the amount of time you have the delay set.
Also, you probably know what happens when you press two keys at the same time. Aaauugggg. Your space ship goes the wrong way.
So we have to create an assembler routine to get this code.
Here is Getkeyh.zip (4k) that includes assembler source, callable from basic, a basic demo to show how to call and use this code, and the quick library to use it in the IDE.
To assemble getkeyh.asm: MASM GETKEYH;
To create getkeyh.qlb: LINK /Q GETKEYH,GETKEYH.QLB,,QBLIB45;
To load it in the IDE: QB /L GETKEYH.QLB GETKEY.BAS
The number returned by the function GETKEYH%, is the hi-order (AH) of the number of the scan code. See newbinfo.zip (16k) for a list of scan codes. For instance: The scan code for 'A' is 1E61h, so the function above would return 1Eh (30d).