test whether or not a keyboard stroke is available
#include <conio.h> int kbhit( void );
The kbhit() function tests whether or not a keystroke is currently available. When one is available, the function getch() or getche() can be used to obtain it.
With a stand-alone program, the kbhit() function can be called continuously until a keystroke is available.
Loops involving the kbhit() function aren't recommended in multitasking systems. |
Zero when no keystroke is available; otherwise, a nonzero value.
/* * This program loops until a key is pressed * or a count is exceeded. */ #include <stdio.h> #include <conio.h> void main() { unsigned long i; printf( "Program looping. Press any key.\n" ); for( i = 0; i < 10000; i++ ) { if( kbhit() ) { getch(); break; } } }
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
getch(), getche(), putch(), ungetch()