Description
GetAsyncChar() is used to retrieve a single character of input from the user.
Call Signature
string GetAsyncChar ( )
Return Value
string
A string of length zero or one, is returned depending on whether a character of pending input was found. See Remarks section.
Remarks
This intrinsic function will return either a single character of input from the user if the user has hit a key, or an empty string if there is no pending input. Unlike the INPUT command, this can be used to get input from the user asynchronously. That is to say, the procedure can check for input without blocking while waiting for it.
The GetAsyncChar() call puts the terminal in a special asynchronous input mode on some systems. Therefore it is critical that AsyncDisable() be called before either terminating a script, attempting to use the INPUT command, or calling a subprocedure or subprogram that attempts to get conventional input from the user.
Example
The following example script will loop waiting for input from the user. Each character is printed out as an ascii value and as a string. When the `q' key is returned, the script terminates, disabling asynchronous input mode. Also note that the script sleeps for a short time when it doesn't get any input in order to avoid "busy waiting" and while waiting for input.
local int bDone
local string response
while( bDone = 0 )
response = GetAsyncChar()
if( f$len(response) = 0 )then
call Sleep( 0.1 )
else
printf "%d {%s}\n", f$ascii(response[1]), response
if( response = "q" )then
bDone = 1
endifg
endif
endwhile
call AsyncDisable()
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.