INKEY$ Does Not Trap Extended Keys; Must Use Softkeys
ID: Q43531
|
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 and MS OS/2, versions 6.0, 6.0b
-
Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2, version 7.0
SUMMARY
The INKEY$ function does not produce a unique KeyboardFlag + Scancode
for the extended keys on the enhanced or extended 101-key keyboard.
For example, INKEY$ produces the same 2-byte code for the LEFT ARROW
key on the numeric keypad as for the extended LEFT ARROW key. The same
applies to the INS, HOME, PGUP, DEL, END, and PGDN keys and to the
other arrow keys. Thus, you cannot trap for the extended keys
separately using the INKEY$ function.
This is not a problem with the INKEY$ function. Normally, an
application's extended keys should behave exactly like the keys'
equivalents on the numeric keypad. You would expect the cursor to move
left if you pressed the LEFT ARROW from the numeric keypad or from the
separate arrow keys.
MORE INFORMATION
To trap the extended keys separately, use the combination of KEY n, ON
KEY(n), and KEY(n) ON statements. The ability to do this is a unique
feature of Basic's key trapping routines. The following code example
demonstrates how to do this:
Code Example
'**** NOTE ******
' For this program to work properly, the NUM LOCK
' and CAPS LOCK keys must be turned off.
'****************
' Define softkeys.
KEY 15, CHR$(&H80) + CHR$(&H4B)
KEY 16, CHR$(&H0) + CHR$(&H4B)
' Handle key events.
ON KEY(1) GOSUB terminate
ON KEY(15) GOSUB keytrap2
ON KEY(16) GOSUB keytrap1
' Turn the keys on.
KEY(1) ON
KEY(15) ON
KEY(16) ON
' Sign on message.
CLS
LOCATE 1, 18
PRINT "PRESS ONE OF THE LEFT ARROW KEYS"
LOCATE 2, 20
PRINT "PRESS F1 TO EXIT THE PROGRAM"
' Loop waiting for keyboard input.
WHILE 1
WEND
finish:
CLS
END
terminate:
RETURN finish
keytrap1:
PRINT "THAT IS THE LEFT ARROW ON THE NUMERIC PAD"
RETURN
keytrap2:
PRINT "THAT IS THE EXTENDED LEFT ARROW KEY"
RETURN
Additional query words:
VBmsdos QuickBas BasicCom
Keywords :
Version : MS-DOS:1.0,4.0,4.0b,4.5; :6.0,6.0b,7.0
Platform : MS-DOS
Issue type :