今天才知道- -有getch()这个东西。。
嗯。方向键是比较特殊的(不用看ASCII代码表了。找不到的,)
你用一个getch是无法获取真正的值的要连续用2个
- #include<iostream>
- #include<string>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int c;
- while(2)
- {c=getch();
- if(c==224)
- {
- c=getch();
- switch(c)
- {
- case 72:cout<<"上";break;
- case 80:cout<<"下";break;
- case 75:cout<<"左";break;
- case 77:cout<<"右";break;
- default:break;
- }
- }
- }
- return 0;
- }
为什会是72 80 75 77这些数?
你自己试下就知道了