How to detect when the user pressed the second row of keys?



I’m using SDL_KEYDOWN to detect when the user has pressed a key. How can I detect when the user pressed the upper letter from a double function key. Example, when I press “2” I can detect it without a problem, how about when I press “@” (on my keyboard “@” is on the same key as “2”) ? key.keysym.sym only shows “2”.

There is any trick to get the ASCII code of for example SHIFT + 2 ?

For now, I use an ugly solution in which I check if the keysym mod is KMOD_SHIFT and I map 2 to @ but this is not a general solution for when the user doesn’t use a standard keyboard.



I don’t think there’s an API in SDL2 for looking up a keycode + modifier.

However, there is SDL_StartTextInput(), and SDL_TEXTINPUT events. You should get a SDL_TEXTINPUT event with the UTF8 for “@” when you press shift + 2 on your keyboard layout. SDL_TEXTINPUT is more general than keyboard up/down events; they also handle things like dead keys and input methods.

Convert SDL2 "scancode" To ASCII Character?