使用getch()方法来获取无缓冲输入字符
#include <iostream>
#include <conio.h>
#include <stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char ch;
int col = 0;
while(1){
ch = getch();
switch(ch){
case 'o':
case 'O':
printf("UP\n");
break;
case 'k':
case 'K':
printf("LEFT\n");
break;
case 'l':
case 'L':
printf("DOWN\n");
break;
case ';':
case ':':
printf("RIGHT\n");
break;
case 'q':
case 'Q':
printf("飘\n");
case 'e':
case 'E':
printf("氮气\n");
case 'w':
case 'W':
printf("W\n");
default:
continue;
}
col++;
if(col == 10){
printf("\n");
col = 0;
}
}
return 0;
}