Using CALL INTERRUPT to Push Characters into Keyboard Buffer
ID: Q50944
|
The information in this article applies to:
-
Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0
-
Microsoft QuickBASIC for MS-DOS, versions 4.0, 4.0b, 4.5
-
Microsoft BASIC Compiler for MS-DOS, versions 6.0, 6.0b
-
Microsoft BASIC Professional Development System (PDS) for MS-DOS, versions 7.0, 7.1
SUMMARY
It is possible in Visual Basic for MS-DOS to push keys into the
keyboard buffer on IBM AT and PS/2 class computers using the
CALL INTERRUPT statement. (This technique will not work on IBM PC
class computers.) This can allow you to create keyboard macros, such
as for training and demonstration sequences in a program. Therefore,
if you were to write a program that required a lot of input from and
interaction with a user, you could also write a training or
demonstration sequence that would show the user what kind of input
your program required, using the method demonstrated below. This
would require filling in the required responses for the user by
pushing the keystrokes into the keyboard buffer.
The information in this article is also included with the Help file
provided with the Standard and Professional Editions of Microsoft
Visual Basic for MS-DOS, version 1.0.
MORE INFORMATION
The interrupt for the key push routine requires both the scan code for
the key and the ASCII value of the character to be pushed. A maximum
of 15 characters can be pushed into the keyboard buffer at one time.
The program shown below, KEYPSH.BAS, sets up a table containing all of
the scan codes for ASCII character values 32 (a space) through 126
(~), and defines the routine PUSHSTRING that will push the passed
string of characters into the keyboard buffer.
Code Example: KEYPSH.BAS
To try this example in VBDOS.EXE:
- From the File menu, choose New Project.
- Copy the code example to the Code window.
- Press F5 to run the program.
' To run this program in the environment, you must invoke the
' environment with the /L switch to load the default Quick library:
' VBDOS.EXE /L for Visual Basic 1.0 for MS-DOS
'
' This program works on IBM AT and PS/2 class computers, but not on
' IBM PC class computers.
DECLARE SUB pushstring (thestring$)
' Use the following include file for Visual Basic 1.0 for MS-DOS:
REM $INCLUDE: 'VBDOS.BI'
' Use the following include file for QuickBasic for MS-DOS:
REM $INCLUDE: 'QB.BI'
' Use the following include file for BX.EXE and QBX.EXE in Basic PDS
' 7.0 for MS-DOS:
REM $INCLUDE: 'QBX.BI'
DIM SHARED scanarray(1 TO 93) AS INTEGER
FOR i% = 1 TO 93 ' Initialize scan code array.
READ scanarray(i%)
NEXT
CALL pushstring("<Key Push!>")
INPUT a$
PRINT a$
' Define Scan Codes for ASCII characters 32 (space) through 126 (~):
REM ! " # $ % & ' ( ) * + , - . /
DATA 57, 2, 40, 4, 5, 6, 8, 40, 10, 11, 9, 13, 51, 12, 52, 53
REM 0 1 2 3 4 5 6 7 8 9
DATA 11, 2, 3, 4, 5, 6, 7, 8, 9, 10
REM : ; < = > ? @
DATA 39, 39, 51, 13, 52, 53, 3
REM A B C D E F G H I J K L M
DATA 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50
REM N O P Q R S T U V W X Y Z
DATA 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
REM [ \ ] ^ _ `
DATA 26, 43, 27, 7, 12, 41
REM a b c d e f g h i j k l m
DATA 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50
REM n o p q r s t u v w x y z
DATA 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
REM { | } ~
DATA 26, 43, 27, 41
SUB pushstring (thestring$) ' Pushes string into keyboard buffer.
DIM inregs AS regtype
DIM outregs AS regtype
stringlen = LEN(thestring$)
IF stringlen > 15 THEN stringlen = 15 ' Maximum buffer size = 15.
FOR i% = 1 TO stringlen
inregs.ax = &H500 ' Subfunction to push character.
ascvalue = ASC(MID$(thestring$, i%, 1))
IF ascvalue >= 32 AND ascvalue <= 126 THEN
'assign scan code to high byte
inregs.cx = scanarray(ascvalue - 31) * 256
inregs.cx = inregs.cx + ascvalue ' Add ASCII code.
CALL interrupt(&H16, inregs, outregs) ' Keyboard interrupt.
END IF
NEXT
END SUB
To compile and link with Microsoft QuickBasic for MS-DOS, versions
4.0, 4.0b, and 4.5; or with Microsoft Basic Compiler for MS-DOS,
versions 6.0 and 6.0b, perform the following:
BC KeyPSH.bas;
LINK KeyPSH.bas,,,BRUNxx.Lib+QB.Lib;
The "xx" in the library name is for the current version of the product
you are using (40, 41, 45, 60, or 61). For Basic Compiler for MS-DOS,
versions 6.0 and 6.0b, use BRUNxxER.LIB (emulation math package) or
BRUNxxAR.LIB (alternate math package). For the alternate math library,
you must compile with the BC /FPa switch. If you compile with BC /O,
link with BCOMxx.LIB instead of BRUNxx.LIB.
To run this program in the QB.EXE environment, you must load the Quick
library QB.QLB as follows:
QB /L QB.QLB
For Basic PDS for MS-DOS, version 7.0, compile and link as follows:
BC KeyPSH.bas;
LINK KeyPSH.bas,,,BRT70ENR.Lib+QBX.Lib;
The above example is for the math emulation, near strings, and real
mode run-time library. The other possible run-time libraries and their
corresponding compiler switches are as follows:
Library Name Compiler Switches Comments
------------ ----------------- --------
BRT70ENR.LIB [default in MS-DOS] Emulation math, near strings
BRT70ANR.LIB /FPa Alternate math, near strings
BRT70EFR.LIB /Fs Emulation math, far strings
BRT70AFR.LIB /FPa /Fs Alternate math, far strings
To use stand-alone libraries, use BCL70xxx.LIB instead of BRT70xxx.LIB
and add the compiler switch BC /O.
For the QBX.EXE version 7.0 environment, use QBX.QLB as follows:
QBX /L QBX.QLB
REFERENCES
For more articles about reading from and writing to the keyboard
buffer, query on the following words in the Knowledge Base:
interrupt and keyboard and buffer
Keyboard scan codes and ASCII codes are documented in Appendix D of
"Microsoft QuickBasic 4.5: Programming in Basic"; in Appendix A of
"Microsoft QuickBasic 4.0: Language Reference" for versions 4.0 and
4.0b; in Appendix A of "Microsoft Basic Compiler 6.0: Language
Reference" for versions 6.0 and 6.0b; and in Appendix A of
"Microsoft Basic 7.0: Language Reference" manual for Basic PDS
versions 7.0 and 7.1. Keyboard scan codes and ASCII codes are
documented in Appendix A of "Microsoft Visual Basic for MS-DOS
Language Reference" for version 1.0.
Additional query words:
VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 6.00 6.00b 7.00 7.10
Keywords :
Version : MS-DOS:1.0,4.0,4.0b,4.5; :6.0,6.0b,7.0,7.1
Platform : MS-DOS
Issue type :
|