The documentation for SDL2's SDL_GetScancodeName has the following remark:
Warning: The returned name is by design not stable across platforms, e.g. the name for SDL_SCANCODE_LGUI is "Left GUI" under Linux but "Left Windows" under Microsoft Windows, and some scancodes like SDL_SCANCODE_NONUSBACKSLASH don't have any name at all. There are even scancodes that share names, e.g. SDL_SCANCODE_RETURN and SDL_SCANCODE_RETURN2 (both called "Return"). This function is therefore unsuitable for creating a stable cross-platform two-way mapping between strings and scancodes.
This presents issues for this project:
An mkxp.json that makes use of the OS-renamed scancodes is not transferable between different operating systems
Any scancodes that have identical string names cannot be consistently bound, which includes the many null scancode names
The repeated scancode names are particularly perplexing, as SDL_GetScancodeFromName just returns a scancode after finding the first match. This means that it is impossible to get SDL_SCANCODE_RETURN2 at all, as it comes after SDL_SCANCODE_RETURN in the scancodes array.
This may not be a massive issue, as the keys affected by this are highly unlikely to be ones the player would bind in a video game (Windows key, numpad enter gives "Keypad Enter", etc.). Should I want to address this anyway, the simplest answer is probably to write the errant scancode names. SDL3 exposes SDL_SetScancodeName, but SDL2 does not. To rectify that, one of the following could be done:
Upgrade to SDL3 (pls no) to access SDL_SetScancodeName and fix the errant scancode names
Fuck it, I use my own fork anyway, directly edit the source to fix these scancode names or at least expose SDL_SetScancodeName
Copy the array into mkxp, edit that array's values to have what I want, then just use that array instead of SDL_GetScancodeFromName
The documentation for SDL2's
SDL_GetScancodeName
has the following remark:This presents issues for this project:
mkxp.json
that makes use of the OS-renamed scancodes is not transferable between different operating systemsThe repeated scancode names are particularly perplexing, as
SDL_GetScancodeFromName
just returns a scancode after finding the first match. This means that it is impossible to getSDL_SCANCODE_RETURN2
at all, as it comes afterSDL_SCANCODE_RETURN
in the scancodes array.This may not be a massive issue, as the keys affected by this are highly unlikely to be ones the player would bind in a video game (Windows key, numpad enter gives "Keypad Enter", etc.). Should I want to address this anyway, the simplest answer is probably to write the errant scancode names. SDL3 exposes
SDL_SetScancodeName
, but SDL2 does not. To rectify that, one of the following could be done:SDL_SetScancodeName
and fix the errant scancode namesSDL_SetScancodeName
SDL_GetScancodeFromName
References