_getch, _getwch
Gets a character from the console without echo.
int _getch( void );
wint_t _getwch( void );
Return Value
Returns the character read. There is no error return.
Remarks
The _getch and_getwch functions read a single character from the console without echoing the character. None of these functions can be used to read CTRL+C. When reading a function key or an arrow key, each function must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code.
These functions lock the calling thread and are therefore thread-safe. For non-locking versions, see _getch_nolock, _getwch_nolock.
Generic-Text Routine Mappings
Tchar.h routine |
_UNICODE and _MBCS not defined |
_MBCS defined |
_UNICODE defined |
---|---|---|---|
_gettch |
_getch |
_getch |
_getwch |
Requirements
Routine |
Required header |
---|---|
_getch |
<conio.h> |
_getwch |
<conio.h> or <wchar.h> |
For more compatibility information, see Compatibility in the Introduction.
Example
// crt_getch.c
// compile with: /c
// This program reads characters from
// the keyboard until it receives a 'Y' or 'y'.
#include <conio.h>
#include <ctype.h>
int main( void )
{
int ch;
_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );
_putch( ch );
_putch( '\r' ); // Carriage return
_putch( '\n' ); // Line feed
}
abcdey
Type 'Y' when finished typing keys: Y
NET Framework Equivalent
Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.