Only function keys get caught by SDL_KEYDOWN and they get printed normally , normal letters and numbers sometimes get caught by SDL_TEXTINPUT(unpredictably) but when i try to print them i get either nothing or things like “Æëçó” , the key dosen’t get caught at all by the if statement . Does anyone have the same problem ?
This is on win 10 Visual Studio 19 and i get the same results when using on screen keyboard .
case SDL_KEYDOWN: //here only ctrl , alt , caps get caught
std::cout << SDL_GetKeyName(g_event->key.keysym.sym); //this prints out the names correctly
case SDL_TEXTINPUT: //here normal keys get caught sometimes(letters,numbers...)
std::cout << SDL_GetKeyName(g_event->key.keysym.sym); //this prints out things like this "ⁿÆëçó" or nothing at all
if(g_event->key.keysym.sym==SDLK_f) //the key isn't caught no matter what
case SDL_TEXTINPUT, the SDL_Event field is text, so you would access the value using
g_event->text.text. Can’t help with the
SDL_KEYDOWN without more information, how are you declaring
g_event and calling
Also, when using
g_event->text.text, you wouldn’t use
SDL_GetKeyName since the text is already a UTF-8 encoded char.
I’m also wondering if the calls to
SDL_GetKeyName is messing up your
std::cout << .... The documentation says the returned pointer is good until the next call to the function, and it looks like you are using the same
g_event memory for both
cases…since the call to
case SDL_TEXTINPUT would occur soon after the
SDL_KEYDOWN, and you aren’t flushing the call to
cout, that could be messing it up. That would match the problems you are seeing since the
SDL_KEYDOWN seems to be working only for keys that don’t generate
SDL_TEXTINPUT events. Try throwing an
std::endl on the end of the
couts or remove the calls to
SDL_GetKeyName. Just guessing here, hope it helps.
Thanks ,i assumed that the separation of sdl_textinput from sdl_keydown was just superficial which was my problem , the documentation isn’t really clear about this but now it all works .