ऐसा करने के लिए पोर्टेबल समाधान मौजूद नहीं है। विंडोज़ पर, आप वर्णों को दबाने के लिए कोनियो (कंसोल I/O) लाइब्रेरी से getch() फ़ंक्शन का उपयोग कर सकते हैं।
उदाहरण
#include<iostream>
#include<conio.h>
using namespace std;
int main() {
char c;
while(1){ // infinite loop
c = getch();
cout << c;
}
} यह आपके द्वारा टर्मिनल में इनपुट किए गए किसी भी वर्ण को आउटपुट करेगा। ध्यान दें कि यह केवल विंडोज़ पर काम करेगा क्योंकि कोनियो लाइब्रेरी केवल विंडोज़ पर मौजूद है। UNIX पर, आप सिस्टम रॉ मोड में प्रवेश करके इसे प्राप्त कर सकते हैं।
उदाहरण
#include<iostream>
#include<stdio.h>
int main() {
char c;
// Set the terminal to raw mode
system("stty raw");
while(1) {
c = getchar();
// terminate when "." is pressed
if(c == '.') {
system("stty cooked");
exit(0);
}
std::cout << c << " was pressed."<< std::endl;
}
}