From 45598620fa0a067e396c29970d7b15ac81d0059d Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Thu, 8 Oct 2015 18:25:28 -0700 Subject: [PATCH] - additional bugfixes for keyboard entry in sdl2 --- .../glest_game/menu/menu_state_keysetup.cpp | 16 ++++++---- .../sources/platform/sdl/window.cpp | 32 ++++++++++++------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/source/glest_game/menu/menu_state_keysetup.cpp b/source/glest_game/menu/menu_state_keysetup.cpp index 8d091cce1..dbbdeb418 100644 --- a/source/glest_game/menu/menu_state_keysetup.cpp +++ b/source/glest_game/menu/menu_state_keysetup.cpp @@ -492,10 +492,11 @@ void MenuStateKeysetup::keyDown(SDL_KeyboardEvent key) { //printf("\nkeyDown [%d]\n",hotkeyChar); string keyName = ""; - if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym); - keyName = SDL_GetKeyName(hotkeyChar); - } + //if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym); + keyName = SDL_GetKeyName(hotkeyChar); + //printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym); + //} //key = hotkeyChar; if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym); @@ -524,6 +525,7 @@ void MenuStateKeysetup::keyDown(SDL_KeyboardEvent key) { char szBuf[8096] = ""; snprintf(szBuf,8096," %s [%s][%d][%d][%d]",keyName.c_str(),utfStr,key.keysym.sym,hotkeyChar,key.keysym.mod); labelTestValue.setText(szBuf); + //printf ("In [%s::%s Line: %d] szBuf [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf); delete [] utfStr; @@ -541,9 +543,9 @@ void MenuStateKeysetup::keyUp(SDL_KeyboardEvent key) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,hotkeyChar,key.keysym.sym); string keyName = ""; - if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) { - keyName = SDL_GetKeyName(hotkeyChar); - } + //if(hotkeyChar > SDLK_UNKNOWN && hotkeyChar < SDL_NUM_SCANCODES) { + keyName = SDL_GetKeyName(hotkeyChar); + //} key.keysym.sym = hotkeyChar; if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] keyName [%s] char [%d][%d]\n",__FILE__,__FUNCTION__,__LINE__,keyName.c_str(),hotkeyChar,key.keysym.sym); diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 865c3bcb9..dbe373767 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -97,7 +97,15 @@ static bool isUnprintableChar(SDL_keysym key) { return true; default: // U+0000 to U+001F are control characters - return (key.sym < 0x20); + /* Don't post text events for unprintable characters */ + if (key.sym > 127) { + return true; + } + if(key.sym < 0x20) { + return true; + } + //printf("isUnprintableChar returns false for [%d]\n",key.sym); + return false; } } @@ -1067,22 +1075,22 @@ vector extractKeyPressedUnicodeLength(string text) { SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input) { SDL_Keycode c = SDLK_UNKNOWN; //if(input.keysym.unicode > 0 && input.keysym.unicode < 0x80) { - if(input.keysym.sym > 0) { - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] input.keysym.sym = %d input.keysym.mod = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,input.keysym.sym,input.keysym.mod); + //if(input.keysym.sym > 0) { + // if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] input.keysym.sym = %d input.keysym.mod = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,input.keysym.sym,input.keysym.mod); - c = input.keysym.sym; + // c = input.keysym.sym; // if(c <= SDLK_UNKNOWN || c >= SDLK_LAST) { // c = SDLKey(c & 0xFF); // } //c = toupper(c); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF)); - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF)); - } - if(c <= SDLK_UNKNOWN) { - c = input.keysym.sym; - } + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF)); + //if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] #1 (c & 0xFF) [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(c & 0xFF)); + //} + //if(c <= SDLK_UNKNOWN) { + c = input.keysym.sym; + //} if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %u] c = [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c); @@ -1093,8 +1101,8 @@ SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input) { string pressKeyName = SDL_GetKeyName(c); //string inputKeyName = SDL_GetKeyName(input.keysym.sym); - //printf ("PRESS pressed key [%d - %s] input.keysym.sym [%d] input.keysym.unicode [%d] mod = %d\n", - // c,pressKeyName.c_str(),input.keysym.sym,input.keysym.unicode,input.keysym.mod); +// printf ("PRESS pressed key [%d - %s] input.keysym.sym [%d] mod = %d\n", +// c,pressKeyName.c_str(),input.keysym.sym,input.keysym.mod); if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] pressed key [%d - %s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c,pressKeyName.c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] pressed key [%d - %s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c,pressKeyName.c_str());