Microsoft KB Archive/64933

= How to Emulate INKEY$ Function by CALLing MS-DOS INTERRUPT =

Article ID: 64933

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBASIC 4.0b, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBasic 4.5 for MS-DOS, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q64933



SUMMARY
The INKEY$ function in QuickBasic can be replaced by the following code example that uses two MS-DOS interrupt service routines. These interrupt routines allow NEWINKEY$ to function the same way that INKEY$ works and return the same results for any given keystroke.

This information applies to Microsoft QuickBasic 4.00, 4.00b, and 4.50 for MS-DOS; to Microsoft Basic Compiler 6.00 and 6.00b for MS-DOS; and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS.



MORE INFORMATION
The following code contains the NEWINKEY$ function, which must be called from Basic in the same manner that INKEY$ is called. '******************************************************************** ' '  Written for Microsoft QuickBasic 4.00, 4.00b, and 4.50; Microsoft '  Basic Compiler 6.00 and 6.00b; and Microsoft Basic PDS 7.00 and '  7.10 for MS-DOS. ' '  This code contains a function (NEWINKEY$) that can be used instead '  of the built-in INKEY$ function. ' '  NEWINKEY$ uses two interrupt calls to retrieve information from '  the keyboard buffer. ' '  The interrupt (INT) service routines are : '  Hexadecimal: INT 16 with Function 11 and INT 16 with Function 10 '  (Decimal   : INT 22 with Function 17 and INT 22 with Function 16) ' '  For more information regarding the functionality of these and '  other interrupts, see &quot;Advanced MS-DOS Programming,&quot; second edition, '  by Ray Duncan (Microsoft Press, 1988). ' *********************************************************************

DECLARE FUNCTION NewInkey$

' Use (uncomment) one of the following two INCLUDE statements: ' ' The following is the include statement for Microsoft QuickBasic ' 4.00, 4.00b, 4.50 or for Microsoft Basic Compiler 6.00 or 6.00b: ' ' REM $INCLUDE: 'QB.BI' ' ' The following is the include statement for Microsoft Basic PDS 7.00 ' or 7.10: ' ' REM $INCLUDE: 'QBX.BI'

FUNCTION NewInkey$

' RegType is defined in the QB.BI (or QBX.BI) include file

DIM Regs AS RegType

' Register AX will contain 1100 Hexadecimal to specify ' the interrupt function to execute. '  ' Function 11 Hexadecimal will get the enhanced keyboard status.

Regs.ax = &H1100 CALL Interrupt(&H16, Regs, Regs)

KeyCode$ = &quot;&quot;

' If the zero flag is clear, then a key was pressed (Bit 6).

IF (Regs.flags AND 2 ^ 6) = 0 THEN

' Call Function 10 Hexadecimal to remove the key from the ' keyboard buffer.

Regs.ax = &H1000 CALL Interrupt(&H16, Regs, Regs)

Scan% = (Regs.ax AND &HFF00) \ 256 AND &HFF Char% = Regs.ax AND &HFF

' Character code of zero is for the special keys (such as     ' function keys F1 through F12.      ' Character code of 224 is for the Enhanced Keyboard keys (such ' as HOME and END keys)

IF Char% = 0 OR Char% = 224 THEN KeyCode$ = CHR$(0) + CHR$(Scan%) ELSE KeyCode$ = CHR$(Char%) END IF  END IF   NewInkey$ = KeyCode$ END FUNCTION

Additional query words: QuickBas BasicCom

Keywords: KB64933

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.