Inkey
 
Returns a string representing the first key waiting in the keyboard buffer

Syntax
Usage

result = Inkey[$]

Return Value

The first character found in the keyboard buffer, or the null string ("") if none found.

Description

Peeks into the keyboard buffer and returns a String representation of the first character, if any, found. The key is then removed from the buffer, and is not echoed to the screen. If the keyboard buffer is empty, the NULL string ("") is immediately returned without waiting for keys.

If the key is in the ASCII character set, a one-character String consisting of that character is returned. If the key is an "extended" one (numeric pad, cursors, functions) a two-character String is returned, the first of which is the extended character (See dialect differences below)

The Shift, Ctrl, Alt, and AltGr keys can't be read independently by this function as they never enter the keyboard buffer (although, perhaps obviously, Shift-A will be reported by Inkey differently than Control-A et cetera; Alt-A is an extended key a la the above).

To wait for a key press, Inkey can be polled in a loop. See also Input or GetKey.

Example

Print "press q to quit"
Do
Loop Until Inkey = "q"


Dialect Differences

  • The extended character is Chr(255) in the -lang fb and -lang fblite dialects.
  • In the -lang qb dialect, the extended character depends on how the keyword is written. If the QB form Inkey$ is used the extended character is Chr(0), while if written as __Inkey the extended char is Chr(255) as in the other dialects.
  • The string type suffix "$" is optional in the -lang fblite and -lang fb dialects.

Differences from QB

  • None in the -lang qb dialect.
  • QBasic returned a Chr(0) as the first character for an extended key, but FreeBASIC returns Chr(255) as the first character in the -lang fb and -lang fblite dialects

See also