Syntax
include <conio.h> int _kbhit(void);Description
This example uses _kbhit to test for the pressing of a key on the keyboard and to print a statement with the test result.
#include <conio.h> #include <stdio.h> int main(void) { int ch; printf("Type in some letters.\n"); printf("If you type in an 'x', the program ends.\n"); for (; ; ) { while (0==_kbhit()){ /* Processing without waiting for a key to be pressed */ } ch = getch(); printf("You have pressed the '%c' key.\n",ch); if ('x' == ch) break; } return 0; /**************************************************************************** The output should be similar to: Type in some letters. If you type in an 'x', the program ends. You have pressed the 'f' key. You have pressed the 'e' key. You have pressed the 'l' key. You have pressed the 'i' key. You have pressed the 'x' key. ****************************************************************************/ }Related Information