Description
Currently, pygame has very little to no support for keyboard layouts besides English. For example, on a French keyboard, the typical WASD is ZQSD and on my layout (German), the Z and the Y are flipped from the English layout. If a game is written to use key codes to trigger actions, this causes problem with people using keyboards other then the one the game was written with. Often the controls are awkward or almost unusable. Yes, the game developer can provide rebindable controls but this is a poor user experience when a user boots up the game for the first time and goes to play and the controls are whacky before they realize they need to change them. The first moments are critical for a game making a good impression and the game should start with the correct control map. This is why games should usually use scan codes which unlike key codes are independent of keyboard layouts. The Z scan code is always the exact same physical key in the same spot no matter the layout. Pygame does allow us to get the scan code from the key input events which is enough to correctly set up input but it does not fully solve the issue. If a game wants to render instructions to the screen, or have a settings menu with rewindable keys, etc. there is no way to figure out what letter is on a physical key. So you can't draw instructions saying "press W, A, S, D to move" on a English computer and "press Z, Q, S, D to move" on a French computer! SDL2 already provides all the functions we need to support this.
I am suggesting (and I am willing to do the work) that pygame adds two new functions: pygame.key.scan_to_key and pygame.key.key_to_scan. They will just take a key code or a scan code and convert them to the opposite. SDL2 already provides those functions via SDL_GetKeyFromScancode and SDL_GetScancodeFromKey. Should be an easy inclusion.
I will start working on this, let me know if anyone wants any other functions or different behavior or if there would be zero intentions to accept my future pull request.
Activity