Hello. I am trying to write a piece of software that supports many different keyboard layouts. In doing this, I have found SDL_GetScancodeFromKey() and SDL_GetKeyFromScancode() invaluable.
I have run into a problem here. I wish to do something when the user presses the key marked with ‘?’. However, if I call SDL_GetScancodeFromKey, it returns 0/unknown. If I look at the docs
I find two sections at the bottom, “These physical keys do not have corresponding virtual key values” and “These virtual key values do not have corresponding physical keys”. Question mark is on the latter list, since there is no “question mark” key but rather a / key with a question mark.
The thing I am trying to get out of the API here is reasonable-- I want to know what scancode corresponds to the button with a ? printed on it, so I can tell if this button has been pressed. There is no way for me to tell if this has happened-- it’s not clear to me if SDLK_QUESTION can ever fire, but surely it will only be if ? is typed, i.e., the appropriate modifier is down. SDL could get me this information-- it has access to the OS keyboard layout APIs and, it seems, must be using them if GetScancodeFromKey works at all. It seems to me SDL ought to express some interface for getting me this information.
Moreover it seems to me that if SDL says that this is not something it wants to be in the business of providing, this is a significant and problematic limitation because it means the GetXFromY functions for keys are fundamentally only truly useful for the U.S. QWERTY keyboard layout. Consider SDLK_COLON. According to the API, SDLK_COLON “does not have a corresponding physical key”. However, on the AZERTY keyboard layout, there is indeed a physical key-- and thus a scancode-- for SDLK_COLON. On the other hand there is not a physical key/scancode for slash in AZERTY, yet the API will allow me to convert SDLK_SLASH to and from scancode on an AZERTY keyboard.
Do these issues I am raising make sense, and is this feature (offering scancodes currently corresponding to the currently “virtual” keycodes) something SDL might consider as a feature in a future version?