#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()) //清空緩沖區(qū)
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;
}
本文摘自 :https://blog.51cto.com/u