Sign in to follow this  
BiiXteR

Pressing a key down generates both KEYDOWN and KEYUP event

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this