_getch _getwch

從主控台取得字元,沒有回應。

重要事項重要事項

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

int _getch( void );
wint_t _getwch( void );

傳回值

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

備註

_getch 和_getwch 函式讀取從主控台的單一字元,而不用回應字元。這些函式都不可以用來讀取 CTRL+C。當讀取功能鍵或方向鍵時,必須呼叫兩次每個函式;第一個呼叫傳回 0 或 0xE0 和第二個呼叫會傳回實際按鍵的程式碼。

這些函式鎖定呼叫的執行緒並具備執行緒安全。如需非鎖定版本,請參閱 _getch_nolock _getwch_nolock

泛用文字常式對應

Tchar.h 常式

未定義的 _UNICODE 和 _MBCS

已定義 _MBCS

已定義 _UNICODE

_gettch

_getch

_getch

_getwch

需求

程序

必要的標頭檔

_getch

<conio.h>

_getwch

<conio.h> 或 <wchar.h>

如需更多關於相容性的資訊,請參閱入門介紹中的 相容性 (Compatibility)

範例

// crt_getch.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 = _getch();
      ch = toupper( ch );
   } while( ch != 'Y' );

   _putch( ch );
   _putch( '\r' );    // Carriage return
   _putch( '\n' );    // Line feed  
}
  

NET Framework 對等

不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需更多的資訊,請參閱 Platform Invoke Examples

請參閱

參考

主控台和連接埠的 I/O

_getche _getwche

_cgets _cgetws

getc getwc

_ungetch、 _ungetwch、 _ungetch_nolock、 _ungetwch_nolock