VOOZH about

URL: https://www.geeksforgeeks.org/c/kbhit-c-language/

⇱ kbhit in C language - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

kbhit in C language

Last Updated : 15 Jan, 2026

The kbhit() functionality basically stands for the Keyboard Hit. This function deals with keyboard pressing. kbhit() is present in conio.h and used to determine if a key has been pressed or not. To use the kbhit function in your program, you should include the header file "conio.h". If a key has been pressed, then it returns a non-zero value; otherwise returns zero. 

Note: kbhit() is not a standard library function and should be avoided.

Example: C++ program to demonstrate use of kbhit()

Output:

"Press a key" will keep printing on the 
console until the user presses a key on the keyboard.

Example: C++ program to fetch key pressed using kbhit()

Output:

Prints all the keys that will be pressed on
 the keyboard until the user presses Escape key

Example: Using include conio.h file for kbhit function

Output :
Enter key ESC to exit
You have entered : i
You have entered : P
You have entered : S
You have entered : w
You have entered : 7
You have entered : /
You have entered : *
You have entered : +

Note: kbhit() is non-standard (Windows-only). For cross-platform key detection, use cin (blocking) or libraries like ncurses/termios for non-blocking input.

Comment
Article Tags: