[SDL] SDL_KEYDOWN event on mouse movement

James Barrett xucaen at gmail.com
Mon Dec 17 14:42:04 PST 2007



David Olofson wrote:
> On Monday 17 December 2007, James Barrett wrote:
>   
>> Hi, I am finding that moving the mouse over an sdl screen is causing
>> the SDL_WaitEvent function to detect an SDL_KEYDOWN event. Has
>> anyone else seen this?
>>     
>
> No, and I'm quite sure that would have confused some of my code...!
>
> Do you have a minimal code example that demonstrates this?
>
>   

It seems to be happening again. When I move the mouse out of the sdl
window it seem like a keyboard event is firing. I am Running debian
linux, and have the debian package for SDL  v 1.2.11-8 installed. I am
noticing that even if I never mouse over the sdl window, but rather
cause the sdl window to gain and lose focus via the gnome panel, looks
like the keyboard event is firing anytime the sdl window loses focus.
The output from my cerr statement is whenever the sdl window loses focus is:

****** KEYBOARD EVENT *******
SDLKey is 300

bool InputSubSystem::PollForEvents()
{
    bool returnValue = false;
    //send to devices for processing
    SDL_Event se;

    bool EventNotProcessed = true;
    while(EventNotProcessed)
    {
        if(SDL_WaitEvent(&se))
        {
            if(isValidEvent(se))
            {
                EventNotProcessed = false;
                returnValue = ProcessEvent(se);
                //flush the input
                SDL_Event event;
                while(SDL_PollEvent(&event));
            }
            else
            {
                EventNotProcessed = true;
            }
        }
    }

    return returnValue;
}

bool InputSubSystem::ProcessEvent(SDL_Event& se)
{
    bool returnValue = false;
    switch(se.type)
    {
    case SDL_KEYDOWN:
    case SDL_KEYUP:
        cerr << "****** KEYBOARD EVENT *******" << endl;
        returnValue = this->k->HandleEvent(se);
        break;
    case SDL_JOYBUTTONDOWN:
    case SDL_JOYBUTTONUP:
        cerr << "****** JOYSTICK BUTTON EVENT *******" << endl;
        this->j[se.jbutton.which]->HandleEvent(se.jbutton);
        break;
    case SDL_JOYAXISMOTION:
        cerr << "****** JOYSTICK AXIS EVENT *******" << endl;
        this->j[se.jaxis.which]->HandleEvent(se.jaxis);
        break;
    }
    return returnValue;
}

bool InputSubSystem::isValidEvent(const SDL_Event& se)
{
    bool returnValue = false;
    switch(se.type)
    {
    case SDL_KEYDOWN:
    case SDL_KEYUP:
    case SDL_JOYBUTTONDOWN:
    case SDL_JOYBUTTONUP:
    case SDL_JOYAXISMOTION:
        returnValue = true;
        break;
    }   
    return returnValue;
}


More information about the SDL mailing list