Jump to content
  • Advertisement
Sign in to follow this  
BiiXteR

Pressing a key down generates both KEYDOWN and KEYUP event

This topic is 888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem where if I press any key on my keyboard, and hold it in it will give me both a KEYDOWN event and right after (without me releasing the key on my keyboard) it will give me a KEYUP event.

 

So, simply it generates both a KEYDOWN and KEYUP event even though I haven't released any key(s).

 

Here's my ProcessInput function : (so sorry for the switch statements, and the 'probably' bad formatting, had to format it all in browser....)

 

void Input::ProcessInput()
{


    if (initialized = true)
    {


        while (SDL_PollEvent(&Input::eventHandler))
        {


            switch (Input::eventHandler.type)
            {


                case SDL_QUIT:
                    SDL_Quit();
                    exit(0);
                    break;


               case SDL_KEYDOWN:


                   std::cout << "KEYDOWN" << std::endl;


                   switch (Input::eventHandler.key.keysym.sym && Input::eventHandler.key.repeat == false)
                   {


                   case SDLK_UP:
                       keys.find(SDLK_UP)->second = true;
                       break;


                   case SDLK_DOWN:
                       keys.find(SDLK_DOWN)->second = true;
                       break;


                   case SDLK_RIGHT:
                       keys.find(SDLK_RIGHT)->second = true;
                       break;


                   case SDLK_LEFT:
                       keys.find(SDLK_LEFT)->second = true;
                       break;


                   default:
                         break;


     }


    case SDL_KEYUP:


           std::cout << "KEYUP" << std::endl;


           switch (Input::eventHandler.key.keysym.sym && Input::eventHandler.key.repeat == false)
           {


            case SDLK_UP:
                 keys.find(SDLK_UP)->second = false;
                 break;


            case SDLK_DOWN:
                 keys.find(SDLK_DOWN)->second = false;
                 break;


            case SDLK_RIGHT:
                 keys.find(SDLK_RIGHT)->second = false;
                 break;


            case SDLK_LEFT:
                keys.find(SDLK_LEFT)->second = false;
                break;


            }
        }
    }


}


    else if (initialized == false)
    {
        Errors::Error("Input isn't initialized, doing it for you...", __FILE__, __LINE__);
        InitializeInput();
    }


}

 

Share this post


Link to post
Share on other sites
Advertisement

Aren't you just missing break; at the end of SDL_KEYDOWN case? Same issue with SDL_KEYUP case.

 

Ohh... lol

Thank you. Spent so much time looking and still didn't notice lol

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!