BASIC Language Reference Manual > Command and Function Reference >

GETCHAR$ Function


Waits for the user to press a key, and then returns a string containing the entered character.


string variable = GETCHAR$

Remarks and Examples

The GETCHAR$ function pauses the program and waits for the user to press a key. If the user has already entered a sequence of characters that have not yet been processed by the program, GETCHAR$ takes the next available character from the keyboard buffer and does not pause the program.

The entered character is returned in a string. The character is not displayed on the screen.

Sample program:

10 PRINT "Press any key."
20 X$ = GETCHAR$
30 PRINT "Thank you. You pressed: "; X$
Press any key.
Thank you. You pressed: J

To test whether the user has pressed a key, without pausing the program to wait for a keystroke, use the INKEY$ function instead. To let the user enter a string or number, use the INPUT function.

Copyright 2006-2008, Kevin Matz, All Rights Reserved.