kbhit

Tests whether a keystroke is currently available

Local Servers:nonblocking
Remote Servers:N/A
Classification:Other
Service:Device I/O

Syntax

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

Return Values

kbhit returns TRUE or FALSE, depending on availability of keystrokes. When a keystroke is available, TRUE is returned. If an error is detected or if no keystrokes are available, FALSE (0) is returned. When an error occurs, errno is set.

Remarks

When a keystroke is available, you can call getch or getche to obtain the keystroke. With a stand-alone program, you can call kbhit continuously until a keystroke is available.

See Also

getch, getche, putch, ungetch

Example

  #include <stdlib.h>  
  #include <nwconio.h>  
  #include <stdio.h>  
   
  main ()  
  {  
     while(!kbhit());  
        printf ("the character is ");  
        getche ();  
        getch ();  
  }