Compartilhar via


_getche, _getwche

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at _getche, _getwche.

Gets a character from the console with echo.

Important

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

Syntax

int _getche( void );  
wint_t _getwche( void );  

Return Value

Returns the character read. There is no error return.

Remarks

The _getche and _getwche functions read a single character from the console with echo, meaning that the character is displayed at the console. 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 _getche_nolock, _getwche_nolock.

Generic-Text Routine Mappings

Tchar.h routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined
_getche _getche _getch _getwche

Requirements

Routine Required header
_getche <conio.h>
_getwche <conio.h> or <wchar.h>

For more compatibility information, see Compatibility.

Example

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

See Also

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