Microsoft KB Archive/30844

= INKEY$ Returns Two-Byte String for Arrow and Function Keys =

Article ID: 30844

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b

-



This article was previously published under Q30844



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:


 * 1) From the File menu, choose New Project.
 * 2) Copy the code example to the Code window.
 * 3) 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 &quot;up arrow key pressed&quot;

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 &quot;Hit F1 To Exit&quot; PRINT:PRINT DO

A$=INKEY$ IF MID$(A$,1,1) <> &quot;&quot; THEN

PRINT A$     PRINT &quot;ASCII Value = &quot;; ASC(A$)

END IF  IF MID$(A$,2,1) <> &quot;&quot; THEN PRINT &quot;ASCII Value = &quot;; ASC(MID$(A$,2,1))

END IF

LOOP UNTIL MID$(A$,2,1) = CHR$(59) END

Additional query words: VBmsdos QuickBas BasicCom

Keywords: KB30844

-

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

© Microsoft Corporation. All rights reserved.