_getche_nolock, _getwche_nolock

 

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

Gets a character from the console, with echo and without locking the thread.

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 _getche_nolock( void );  
wint_t _getwche_nolock( void );  

Returns the character read. There is no error return.

_getche_nolock and _getwche_nolock are identical to _getche and _getwche except that they not protected from interference by other threads. They might be faster because they do not incur the overhead of locking out other threads. Use these functions only in thread-safe contexts such as single-threaded applications or where the calling scope already handles thread isolation.

Generic-Text Routine Mappings

Tchar.h routine_UNICODE and _MBCS not defined_MBCS defined_UNICODE defined
_gettche_nolock_getche_nolock_getch_nolock_getwche_nolock
RoutineRequired header
_getche_nolock<conio.h>
_getwche_nolock<conio.h> or <wchar.h>

For more compatibility information, see Compatibility.

// crt_getche_nolock.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_nolock();  
      ch = toupper( ch );  
   } while( ch != 'Y' );  
  
   _putch_nolock( ch );  
   _putch_nolock( '\r' );    // Carriage return  
   _putch_nolock( '\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
_cgets, _cgetws
getc, getwc
_ungetch, _ungetwch, _ungetch_nolock, _ungetwch_nolock

Show: