This is the table of scan codes and key codes that SDL can present the program with:
but there are some oddities — such as the SDL_SCANCODE_GRAVE / SDLK_BACKQUOTE where it notes:
"`" (Located in the top left corner (on both ANSI and ISO keyboards). Produces GRAVE ACCENT and TILDE in a US Windows layout and in US and UK Mac layouts on ANSI keyboards, GRAVE ACCENT and NOT SIGN in a UK Windows layout, SECTION SIGN and PLUS-MINUS SIGN in US and UK Mac layouts on ISO keyboards, SECTION SIGN and DEGREE SIGN in a Swiss German layout (Mac: only on ISO keyboards), CIRCUMFLEX ACCENT and DEGREE SIGN in a German layout (Mac: only on ISO keyboards), SUPERSCRIPT TWO and TILDE in a French Windows layout, COMMERCIAL AT and NUMBER SIGN in a French Mac layout on ISO keyboards, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French Mac layout on ANSI keyboards.)
… yeah, *that* makes it easy to figure out what one ought to do with that key!
Indeed, if you’re using the US English keyboard on a Mac laptop it produces
scancode 53 (`) keycode 96 (`) mod 0
and if you switch to German layout on a US English keyboard it produces
scancode 53 (`) keycode 60 (<) mod 0
which is consistent with what it says in the last clause above (I think my US mac has an ANSI physical keyboard layout), except that SDL isn’t going to resolve the shift modifier, so you have to guess - the SDL people don’t think you should know the layout. See https://github.com/libsdl-org/SDL/issues/5977 - for *some* things you can look at the “textinput” event instead of the “key” event, but if the control key is pressed you don’t get the “textinput” event (which in the non-control case gives you the UTF-8 encoded string for the shift-resolved character)
The other thing to consider is that *if* SDL is talking to an X11 server as its display backend… it looks at the X11 modmap settings (the same one that is NOT completely correct when you’re talking to XQuartz) and tries to figure out what the physical keyboard layout is based on the map it found… essentially the same kind of opaque code that we have in the lde X11 keyboard mapping. And it can get confused if you remap to many of the “wrong” keys. I’m not sure what it does when it is deal with native Cocoa windows/input.
Sigh.
— Nick