_kbhit
檢查主控台輸入。
重要
這個 API 不能用於 Windows 執行階段執行的應用程式。如需詳細資訊,請參閱 CRT 函式不支援使用 /ZW。
int _kbhit( void );
傳回值
如果按下按鍵時,_kbhit 會傳回非零的值。 否則,會傳回 0。
備註
_kbhit 功能驗證新按鍵的主控台。 如果函式傳回非零的值,按鍵緩衝區等候。 程式可以呼叫 _getch 或 _getche 取得按鍵輸入。
需求
程序 |
必要的標頭檔 |
---|---|
_kbhit |
<conio.h> |
如需更多關於相容性的資訊,請參閱入門介紹中的 相容性 (Compatibility) 。
程式庫
所有的 C 執行階段程式庫 (C run-time libraries) 版本。
範例
// crt_kbhit.c
// compile with: /c
/* This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/
#include <conio.h>
#include <stdio.h>
int main( void )
{
/* Display message until key is pressed. */
while( !_kbhit() )
_cputs( "Hit me!! " );
/* Use _getch to throw key away. */
printf( "\nKey struck was '%c'\n", _getch() );
}
範例輸出
Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!!
Key struck was 'q'