_kbhit

Description

Checks the console for keyboard input.

#include <conio.h> Required only for function declarations  

int _kbhit( void );

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.

Return Value

The _kbhit function returns a nonzero value if a key has been pressed. Otherwise, it returns 0.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

Example

/* KBHIT.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>

void 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() );

_getch();

}

Output

Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!! Hit me!!

Key struck was 'k'