InKey$ Function

Purpose

Reads a character from the keyboard (excluding special keys like Shift, Alt, Alt Gr, Ctrl...).

Syntax

string = InKey[$]

Description

InKey$ does not wait for a key press but, if no keys were pressed since the last keyboard request (by the processor), it returns an empty string. Otherwise, InKey$ reports the ASCII code of the pressed key.

If the pressed key has no ASCII code (the special keys, for example), the scan code of the pressed key is returned instead. If this is this case a two character string is returned, the first of which is a Chr$(0) and the second the corresponding key code.

For a list of Scan and ASCII codes, see Key Codes and ASCII Values.

Example

Local t$

OpenW # 1

Do

t$ = InKey$

Exit If Cvi(t$) = 6912 // Press Esc to quit

If t$ <> ""

If Len(t$) = 1             //normal key

Print "Key: "; t$; Spc(3);

Print "ASCII code : "; Asc(t$)

Else

Print "Chr$(0), Scan code : "; Cvi(t$)

EndIf

EndIf

Loop

CloseW # 1

This example displays the ASCII or scan code for each pressed key.

Remarks

Instead of InKey you should use the Ocx event subs:

Sub Form_KeyDown(Code&, Shift&)

Sub Form_KeyPress(Ascii&)

Sub Form_KeyUp(Code&, Shift&)

Sub Screen_KeyPreview(hWnd%, uMsg%, wParam%, lParam%, Cancel?)

See Also

Keyget, KeyTest

{Created by Sjouke Hamstra; Last updated: 10/10/2014 by James Gaite}