_getche_nolock、_getwche_nolock

从控制台获取字符,无需重复和锁定线程。

重要

此 API 不能用于在 Windows 运行时中执行的应用程序。有关详细信息,请参见 CRT functions not supported with /ZW(CRT 函数不支持使用/ZW)。

int _getche_nolock( void );
wint_t _getwche_nolock( void );

返回值

返回读取的字符。 无错误返回。

备注

_getche_nolock 和 _getwche_nolock 分别与 _getche 和 _getwche是相同的,除了它们不能避免来自其他线程的干扰。 它们可能更快,因为它们不会产生锁定其他线程的开销。 仅在线程安全的上下文中使用这些函数,如单线程应用程序或调用范围已经处理线程隔离。

一般文本例程映射

Tchar.h 例程

未定义 _UNICODE 和 _MBCS

已定义 _MBCS

已定义 _UNICODE

_gettche_nolock

_getche_nolock

_getch_nolock

_getwche_nolock

要求

例程

必需的标头

_getche_nolock

<conio.h>

_getwche_nolock

<conio.h> 或 <wchar.h>

有关兼容性的更多信息,请参见兼容性

示例

// 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 
}
  

.NET Framework Equivalent

不适用。 若要调用标准 C 函数,请使用 PInvoke。 有关更多信息,请参见平台调用示例

请参见

参考

控制台和端口 I/O

_cgets、_cgetws

getc、getwc

_ungetch、_ungetwch、_ungetch_nolock、_ungetwch_nolock