_getch_nolock, _getwch_nolock
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

_getch_nolock, _getwch_nolock

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

int _getch_nolock( void );
wint_t _getwch_nolock( void );

Returns the character read. There is no error return.

_getch_nolock and _getwch_nolock are identical to _getch and_getchw 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






Required header




<conio.h> or <wchar.h>

For more compatibility information, see Compatibility in the Introduction.

// crt_getch_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: " );
      ch = _getch_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.

© 2016 Microsoft