Inkey()

Syntax

String$ = Inkey()
Description
Returns a character string if a key is pressed during the call of Inkey(). It doesn't interrupt (halt) the program flow. If special keys (non-ASCII) have to be handled, RawKey() should be called after Inkey().

Parameters

None.

Return value

Returns a string containing the pressed character if it is a non-special key, and an empty string otherwise.

Example

  If OpenConsole()
    PrintN("Press Escape to exit")
  
    Repeat
      KeyPressed$ = Inkey()
      
      If KeyPressed$ <> ""
        
        PrintN("You pressed: " + KeyPressed$)
        PrintN("It has a raw code of: "+Str(RawKey()))
        
      ElseIf RawKey()
      
        PrintN("You pressed a non ASCII key.")
        PrintN("It has a raw code of: "+Str(RawKey()))
        
      Else
        Delay(20) ; Don't eat all the CPU time, we're on a multitask OS
      EndIf
    
    Until KeyPressed$ = Chr(27) ; Wait until escape is pressed
  EndIf

Remarks

The ASCII codes and numeric values reported in this description may change depending on the code page you have configured at boot time for keyboard input. However, the concepts should be the same and you can use the above example to figure out the real values for your system.

A table with ASCII codes is available here.

See Also

RawKey(), Input()

Supported OS

All

<- EnableGraphicalConsole() - Console Index - Input() ->