共用方式為


_getche_nolock、_getwche_nolock

以用 echo 但不用鎖定執行緒的方式,從主控台取得字元。

重要

這個應用程式開發介面不能用於 Windows 執行階段執行的應用程式。如需詳細資訊,請參閱 /ZW 不支援 CRT 函式

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

傳回值

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

備註

_getche_nolock 和 _getwche_nolock 與 _getche 和 _getwche 除了他們不會預防被其他執行續干擾之外都是一樣的。 因為它們不會造成鎖定其他執行緒的額外負荷,所以可能會比較快。 這些函式只能用在安全執行緒內容 (例如單一執行緒應用程式) 或呼叫範圍已經處理執行緒隔離的地方。

一般文字常式對應

Tchar.h 常式

未定義 _UNICODE and _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 對等

不適用。 若要呼叫標準 C 函式,請使用 PInvoke。 如需詳細資訊,請參閱平台叫用範例

請參閱

參考

主控台和連接埠 I/O

_cgets、_cgetws

getc、getwc

_ungetch、_ungetwch、_ungetch_nolock、_ungetwch_nolock