Share via


_getche_nolock_getwche_nolock

在有回應但不鎖定的情形下,從主控台取得字元。

重要

這個 API 不能用於在 Windows 執行階段中執行的應用程式。 如需詳細資訊,請參閱 CRT functions not supported in Universal Windows Platform apps (通用 Windows 平台應用程式中不支援的 CRT 函式)。

語法

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

傳回值

傳回讀取的字元。 不會傳回錯誤。

備註

_getche_nolock_getwche_nolock 等於 _getche_getwche,不同之處在於它們未受保護,會受到其他執行緒的干擾。 因為其不會造成鎖定其他執行緒的額外負荷,所以可能會比較快。 這些函式只能用在安全執行緒內容 (例如單一執行緒應用程式) 或呼叫範圍已經處理執行緒隔離的地方。

根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態

一般文字常式對應

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
}
abcdefy
Type 'Y' when finished typing keys: abcdefyY

另請參閱

主控台和連接埠 I/O
_cgets, _cgetws
getc, getwc
_ungetch_ungetwch_ungetch_nolock_ungetwch_nolock