Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

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


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???
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900