Eblo / mkxp-z-eulogy

Fork from mkxp-z for Eulogy of an Insect
https://github.com/mkxp-z/mkxp-z/wiki
GNU General Public License v2.0
1 stars 0 forks source link

SDL two-way input mapping issues #4

Open Eblo opened 4 months ago

Eblo commented 4 months ago

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:

  1. An mkxp.json that makes use of the OS-renamed scancodes is not transferable between different operating systems
  2. 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:

References