Checks the console for keyboard input.
int _kbhit( void );
Return Value
_kbhit returns a nonzero value if a key has been pressed. Otherwise, it returns 0.
Remarks
The _kbhit function checks the console for a recent keystroke. If the function returns a nonzero value, a keystroke is waiting in the buffer. The program can then call _getch or _getche to get the keystroke.
Requirements
RoutineRequired headerCompatibility
_kbhit<conio.h>Win 98, Win Me, Win NT, Win 2000, Win XP
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// 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() );
}
Sample Output
Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!!
Key struck was 'q'
'c_c++' 카테고리의 다른 글
[공유] STL 소스 및 도움말, 메뉴얼 관련 사이트 (0) | 2015.11.23 |
---|---|
[C] console 에서의 간단한 실행시간 체크 프로그램 (0) | 2015.11.23 |
[공유] 무료 C++ 컴파일러(Compiler) (0) | 2015.11.23 |
clock 을 사용한 수행시간 산출 (0) | 2015.11.23 |
gcc option (0) | 2015.11.23 |