[Previous]
[Contents]
[Next]

kbhit()

test whether or not a keyboard stroke is available

Synopsis:

#include <conio.h>
int kbhit( void );

Description:

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.


Note: Loops involving the kbhit() function aren't recommended in multitasking systems.

Returns:

Zero when no keystroke is available; otherwise, a nonzero value.

Examples:

/*
 * 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;
      }
    }
  }

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

getch(), getche(), putch(), ungetch()


[Previous]
[Contents]
[Next]