_getch, _getwch


For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Gets a character from the console without echo.

System_CAPS_ICON_important.jpg Important

This API cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

int _getch( void );  
wint_t _getwch( void );  

Returns the character read. There is no error return.

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
RoutineRequired header
_getwch<conio.h> or <wchar.h>

For more compatibility information, see Compatibility.

// 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: " );  
      ch = _getch();  
      ch = toupper( ch );  
   } while( ch != 'Y' );  
   _putch( ch );  
   _putch( '\r' );    // Carriage return  
   _putch( '\n' );    // Line feed    

abcdeyType 'Y' when finished typing keys: Y  

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

Console and Port I/O
_getche, _getwche
_cgets, _cgetws
getc, getwc
_ungetch, _ungetwch, _ungetch_nolock, _ungetwch_nolock