Skip to main content

I use SDL quite a bit but I never use the PumpEvents function. I find that SDL_PollEvent() is the best way to go for SDL input.

Check out the following code, hopefully this helps you with your problem:

bool getKeyState(const char* key)
{
    bool status = false;

    const Uint8* keyboard = SDL_GetKeyboardState(NULL);

    if (keyboard[SDL_GetScancodeFromName(key)]) {
        status = true;
        // If you want to print out the key press details
        //std::cout << "Key pressed: " << SDL_GetScancodeName(scanCode) << " (Scancode: " << scanCode << ")" << std::endl; 
}

    return status;
}

int main()
{
    bool running = true;
    SDL_Event events;

    while (running)
    {
        SDL_PollEvents(events);

        if (getKeyState('C'"C"))
        {
            // will trigger if C is pressed, put your action here
        }
    }

}

I use SDL quite a bit but never use the PumpEvents function. I find that SDL_PollEvent() is the best way to go for SDL input.

Check out the following code, hopefully this helps you with your problem:

bool getKeyState(const char* key)
{
    bool status = false;

    const Uint8* keyboard = SDL_GetKeyboardState(NULL);

    if (keyboard[SDL_GetScancodeFromName(key)]) {
        status = true;
        // If you want to print out the key press details
        //std::cout << "Key pressed: " << SDL_GetScancodeName(scanCode) << " (Scancode: " << scanCode << ")" << std::endl; 
}

    return status;
}

int main()
{
    bool running = true;
    SDL_Event events;

    while (running)
    {
        SDL_PollEvents(events);

        if (getKeyState('C')
        {
            // will trigger if C is pressed, put your action here
        }
    }

}

I use SDL quite a bit but I never use the PumpEvents function. I find that SDL_PollEvent() is the best way to go for SDL input.

Check out the following code, hopefully this helps you with your problem:

bool getKeyState(const char* key)
{
    bool status = false;

    const Uint8* keyboard = SDL_GetKeyboardState(NULL);

    if (keyboard[SDL_GetScancodeFromName(key)]) {
        status = true;
        // If you want to print out the key press details
        //std::cout << "Key pressed: " << SDL_GetScancodeName(scanCode) << " (Scancode: " << scanCode << ")" << std::endl; 
}

    return status;
}

int main()
{
    bool running = true;
    SDL_Event events;

    while (running)
    {
        SDL_PollEvents(events);

        if (getKeyState("C"))
        {
            // will trigger if C is pressed, put your action here
        }
    }

}
Source Link

I use SDL quite a bit but never use the PumpEvents function. I find that SDL_PollEvent() is the best way to go for SDL input.

Check out the following code, hopefully this helps you with your problem:

bool getKeyState(const char* key)
{
    bool status = false;

    const Uint8* keyboard = SDL_GetKeyboardState(NULL);

    if (keyboard[SDL_GetScancodeFromName(key)]) {
        status = true;
        // If you want to print out the key press details
        //std::cout << "Key pressed: " << SDL_GetScancodeName(scanCode) << " (Scancode: " << scanCode << ")" << std::endl; 
}

    return status;
}

int main()
{
    bool running = true;
    SDL_Event events;

    while (running)
    {
        SDL_PollEvents(events);

        if (getKeyState('C')
        {
            // will trigger if C is pressed, put your action here
        }
    }

}