GetAsyncKeyState函数的问题 [英] Problem with GetAsyncKeyState Function

查看:85
本文介绍了GetAsyncKeyState函数的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

Hey,

//Function()

int Login_student::Switch_NP()                 //function in some student class
{
	int Button_Pressed=0;
	
	if(GetAsyncKeyState(VK_DOWN)!=0)
		Button_Pressed=1;
	else if(GetAsyncKeyState(VK_UP)!=0)
		Button_Pressed=10;
	else if(GetAsyncKeyState(VK_BACK)!=0)
		Button_Pressed=11;
	return Button_Pressed;
}
//in main()
while(1)
    {
        int num=Student.Switch_NP();     //Function for getting key(given above)
        switch(num)
            {
            case 1:                         //Down-key pressed Case
            {
                //it should run one time only
                break;
            }
            case 10:                            //Up-key Pressed
            {
                //it should run one time only
                break;
            }
            case 11:                           //Back_Space Pressed
            {
                //it should run one time only
                break;
            }
            default:
            {
                if(GetAsyncKeyState(VK_RETURN)!=0)       //Return key pressed
                {
                    //it should run one time only
                }
                break;
            }
        }
    }



我想问一下,当我按下琴键1(琴键盖)时,它会运行五到六次,是否有任何功能可以释放键盘的所有琴键?



I want to ask, when i press down key, case 1 (down key case), it runs five to six times , is there any function through which i can release all keys of keyboard???

推荐答案

请参见此处的备注 [ ^ ].对于您的项目而言,这不是理想的功能,因为代码的运行速度将比更改键状态快得多.我不确定您要做什么,但是从控制台进行的一些简单输入很可能会满足您的要求.
See the remarks here[^]. This is not an ideal function for your project, since the code will run much faster than the change in keystate. I am not sure exactly what you are trying to do, but some simple input from the console will most likely satisfy your requirements.


这篇关于GetAsyncKeyState函数的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆