Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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;
            }
        }
    }
 
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 22-Nov-12 23:40pm
saad_lah1.1K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100