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
", cc);
            if(cc == 'y'){
                break;
            }
            else{
                printf("q_old = %c
", old);
            }
        }
        system("cls");
        printf("%c
", c);
        old = c;
        printf("old=%c
",old);
    }
    return 0;
}

 http://blog.csdn.net/zz457887107/article/details/6612034

原文地址:https://www.cnblogs.com/fish7/p/7667024.html