INKEY$ Returns Two-Byte String for Arrow and Function Keys
ID: Q30844
|
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 1.0, 1.01, 2.0, 2.01, 3.0, 4.0, 4.0b, 4.5
-
Microsoft BASIC Compiler for MS-DOS and MS OS/2, versions 6.0, 6.0b
SUMMARY
The INKEY$ function returns a one- or two-byte string. Alphanumeric
keys return one-byte strings. The function keys and the directional
keys return two-byte strings.
If INKEY$ returns a two-byte string, then each byte needs to be
examined to determine the key that was pressed. For two-byte strings,
the first byte will always be null [an ASCII value of zero, CHR$(0)],
and the second byte will be the key's scan code. The LEN function
tells you the length of the returned string (one byte or two).
The ASCII and keyboard scan codes are listed in Appendix A of the
Microsoft Visual Basic version 1.0 for MS-DOS Reference Manual.
MORE INFORMATION
To execute the following examples in VBDOS.EXE, use the steps listed
below:
- From the File menu, choose New Project.
- Copy the code example to the Code window.
- Press F5 to run the program.
Example 1
The following sample code prints a message if the UP ARROW key is
pressed:
top:
I$ = INKEY$
'The scan code for the UP ARROW is &H48:
IF I$ = CHR$(0) + CHR$(&H48) THEN
PRINT "up arrow key pressed"
END IF
GOTO top
Example 2
The following code example shows how to print the ASCII value of any
key pressed:
REM ASCII.BAS
CLS
PRINT "Hit F1 To Exit"
PRINT:PRINT
DO
A$=INKEY$
IF MID$(A$,1,1) <> "" THEN
PRINT A$
PRINT "ASCII Value = "; ASC(A$)
END IF
IF MID$(A$,2,1) <> "" THEN
PRINT "ASCII Value = "; ASC(MID$(A$,2,1))
END IF
LOOP UNTIL MID$(A$,2,1) = CHR$(59)
END
Additional query words:
VBmsdos QuickBas BasicCom
Keywords :
Version : MS-DOS:1.0,1.01,2.0,2.01,3.0,4.0,4.0b,4.5; :6.0,6.0b
Platform : MS-DOS
Issue type :