c++ get keyboard event
#include <string> #include <iostream> #include "windows.h" #include <conio.h> #include <time.h> #include "stdio.h" using namespace std; int main() { char old; while(1){ char c = getch(); if (c == 'q'){ char cc; do{ system("cls"); printf("are you sure to quit?(y/n)"); cc = getch(); printf("++%c",cc); } while(cc != 'y' && cc !='n'); printf("q cc=%c\n", cc); if(cc == 'y'){ break; } else{ printf("q_old = %c\n", old); } } system("cls"); printf("%c\n", c); old = c; printf("old=%c\n",old); } return 0; }
http://blog.csdn.net/zz457887107/article/details/6612034