• 當前位置:首頁 > IT技術 > 微信平臺 > 正文

    提供個小程序,得到按鍵值的,做小游戲啥的用
    2021-08-05 12:38:03

    #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;
    }

    本文摘自 :https://blog.51cto.com/u

    開通會員,享受整站包年服務
    国产呦精品一区二区三区网站|久久www免费人咸|精品无码人妻一区二区|久99久热只有精品国产15|中文字幕亚洲无线码