Question

I'm using this code to to determine keyboard inputs as unicode character:

while(SDL_PollEvent(&event))
{
    switch (event.type)
    {
        case SDL_KEYDOWN:
        {
            SDL_KeyboardEvent* keyboard = (reinterpret_cast<SDL_KeyboardEvent*> (&event));

            //unicode input
            std::cout << (int)keyboard->keysym.unicode << std::endl;

            //conversion
            ...

            break;
        }
    }
}

My problem is that keysym.unicode has also a value if I would only press the Shift-key (printed value is 1249).

But I only need valid unicode-charactars (e.g.: pressing Shift+A)

Any hints?

Was it helpful?

Solution

I fixed it using: SDL_StartTextInput(); to enable textinput-events with:

SDL_TEXTINPUT-event instead of SDL_KEYDOWN is working fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top