From 97e509b8ef0243a1ae5fc38b6eea3642a31ff0e3 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sat, 8 Jan 2022 06:37:55 -0500 Subject: [PATCH] Added code to escape keyboard gamepad bindings if the key name interferes with the config file syntax. Fixes save/load of comma key gamepad bindings. For issue #443 --- src/drivers/Qt/sdl-joystick.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/drivers/Qt/sdl-joystick.cpp b/src/drivers/Qt/sdl-joystick.cpp index a2eb333a..a3b98379 100644 --- a/src/drivers/Qt/sdl-joystick.cpp +++ b/src/drivers/Qt/sdl-joystick.cpp @@ -282,6 +282,10 @@ int nesGamePadMap_t::parseMapping(const char *map) while ((map[i] != 0) && (map[i] != ',')) { + if ( map[i] == '\\' ) + { // next character should be interpretted literally + i++; + } val[k][j] = map[i]; i++; j++; @@ -924,7 +928,24 @@ int GamePad_t::saveCurrentMapToFile(const char *name) { if (bmap[c][i].ButtType == BUTTC_KEYBOARD) { - sprintf(stmp, "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum)); + int j=0,k=0; const char *keyName; + + keyName = SDL_GetKeyName(bmap[c][i].ButtonNum); + + stmp[k] = 'k'; k++; + + // Write keyname in with necessary escape characters. + while ( keyName[j] != 0 ) + { + if ( (keyName[j] == '\\') || (keyName[j] == ',') ) + { + stmp[k] = '\\'; k++; + } + stmp[k] = keyName[j]; k++; j++; + } + stmp[k] = 0; + + //sprintf(stmp, "k%s", SDL_GetKeyName(bmap[c][i].ButtonNum)); } else {