#include <conio.h>
//#include <stdio.h>
#include<iostream>
using namespace std;
short int getkey()//得到按键值
{
union key
{
unsigned short int value;
unsigned char ch[2];
} key1;
key1.value =0;
while(kbhit()) //清空缓冲区
getch();
while(!kbhit()); //等待按键
if (kbhit())
{
key1.ch[0]=getch();
if (kbhit())
key1.ch[1]=getch();
}
return key1.value;
}
int main()
{
while(1)
{
short int key;
key=getkey();
cout<<key<<endl;
}
return 0;
}
提供个小程序,得到按键值的,做小游戏啥的用
最新推荐文章于 2024-05-25 16:15:00 发布