यहां हम सी में kbhit कार्यक्षमता देखेंगे। kbhit मूल रूप से कीबोर्ड हिट है। यह फ़ंक्शन conio.h हेडर फ़ाइल में मौजूद है। तो इसका इस्तेमाल करने के लिए हमें इस हेडर फाइल को अपने कोड में शामिल करना होगा।
kbhit() की कार्यक्षमता यह है कि, जब कोई कुंजी दबाया जाता है तो वह शून्येतर मान देता है, अन्यथा शून्य लौटाता है।
उदाहरण
#include <stdio.h> #include <conio.h> main() { char ch; printf("Enter keys (ESC to exit)\n"); while (1) { //define infinite loop for taking keys if (kbhit) { ch = getch(); // Get typed character into ch if ((int)ch == 27) //when esc button is pressed, then it will comeout from loop break; printf("You have entered : %c\n", ch); } } }
आउटपुट
Enter keys (ESC to exit) You have entered : i You have entered : t You have entered : D You have entered : w You have entered : 5 You have entered : / You have entered : * You have entered : + You have entered : You have entered : o You have entered : You have entered : &
नोट: यह kbhit() एक मानक पुस्तकालय नहीं है। इसलिए हमें अपने कोड में इससे बचना चाहिए।