diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index 3c57fa154..8f8efe04c 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -113,7 +113,8 @@ void ChatManager::keyDown(SDL_KeyboardEvent key) { if(isKeyPressed(SDLK_RETURN,key) == true) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym,key.keysym.sym); - SDL_keysym keystate = Window::getKeystate(); + //SDL_keysym keystate = Window::getKeystate(); + SDL_keysym keystate = key.keysym; if(keystate.mod & (KMOD_LALT | KMOD_RALT)){ // alt+enter is ignored SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym,key.keysym.sym); @@ -185,7 +186,7 @@ void ChatManager::keyPress(SDL_KeyboardEvent c) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,c.keysym.sym,c.keysym.sym); //space is the first meaningful code SDLKey key = extractKeyPressed(c); - if(key >= SDLK_SPACE) { + if(isAllowedInputTextKey(key)) { char szCharText[20]=""; sprintf(szCharText,"%c",key); char *utfStr = String::ConvertToUTF8(&szCharText[0]); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index c76aa6d63..f9e98a449 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -777,7 +777,8 @@ void MainWindow::eventMouseWheel(int x, int y, int zDelta) { void MainWindow::eventKeyDown(SDL_KeyboardEvent key) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym); - SDL_keysym keystate = Window::getKeystate(); + //SDL_keysym keystate = Window::getKeystate(); + SDL_keysym keystate = key.keysym; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c][%d]\n",__FILE__,__FUNCTION__,__LINE__,key,key); diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index be84df1c5..6a445613b 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -2146,6 +2146,7 @@ void MenuStateConnectedGame::keyPress(SDL_KeyboardEvent c) { SDLKey key = extractKeyPressed(c); //if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || // (c=='-') || (c=='(') || (c==')')) { + if(isAllowedInputTextKey(key)) { if(activeInputLabel->getText().size() < maxTextSize) { string text= activeInputLabel->getText(); @@ -2161,7 +2162,7 @@ void MenuStateConnectedGame::keyPress(SDL_KeyboardEvent c) { needToSetChangedGameSettings = true; lastSetChangedGameSettings = time(NULL); } - //} + } } } } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index c6fe8c494..a14a7f13b 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2956,6 +2956,7 @@ void MenuStateCustomGame::keyPress(SDL_KeyboardEvent c) { SDLKey key = extractKeyPressed(c); //if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || // (c=='-') || (c=='(') || (c==')')) { + if(isAllowedInputTextKey(key)) { if(activeInputLabel->getText().size() < maxTextSize) { string text= activeInputLabel->getText(); //text.insert(text.end()-1, key); @@ -2973,7 +2974,7 @@ void MenuStateCustomGame::keyPress(SDL_KeyboardEvent c) { lastSetChangedGameSettings = time(NULL); } } - //} + } } } } diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index 7ae8fe3f9..ecdd6f14a 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -711,6 +711,7 @@ void MenuStateOptions::keyPress(SDL_KeyboardEvent c) { // no master server breaks, and a russian translation with game switched to KOI-8p encoding? probably irc too. // (use Shared::Platform::charSet in shared_lib/include/platform/sdl/gl_wrap.h ?) //(c=='-')||(c=='(')||(c==')')){ + if(isAllowedInputTextKey(key)) { if(activeInputLabel->getText().size()getText(); //text.insert(text.end()-1, key); @@ -722,7 +723,7 @@ void MenuStateOptions::keyPress(SDL_KeyboardEvent c) { activeInputLabel->setText(text); } - //} + } } } else { diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index f08b0e26f..c3f26f066 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -226,7 +226,8 @@ void MenuStateRoot::keyDown(SDL_KeyboardEvent key) { } //else if(mainMessageBox.getEnabled() == true && key == vkReturn) { else if(mainMessageBox.getEnabled() == true && isKeyPressed(SDLK_RETURN,key) == true) { - SDL_keysym keystate = Window::getKeystate(); + //SDL_keysym keystate = Window::getKeystate(); + SDL_keysym keystate = key.keysym; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] keystate.mod [%d]\n",__FILE__,__FUNCTION__,__LINE__,keystate.mod); //printf("---> keystate.mod [%d]\n",keystate.mod); diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 97ce7e5be..0f7910e31 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -125,7 +125,7 @@ public: static void setupGraphicsScreen(int depthBits=-1, int stencilBits=-1, bool hardware_acceleration=false, bool fullscreen_anti_aliasing=false); static const bool getIsFullScreen() { return isFullScreen; } static void setIsFullScreen(bool value) { isFullScreen = value; } - static SDL_keysym getKeystate() { return keystate; } + //static SDL_keysym getKeystate() { return keystate; } Window(); virtual ~Window(); @@ -197,7 +197,7 @@ private: bool isKeyPressed(SDLKey compareKey, SDL_KeyboardEvent input); SDLKey extractKeyPressed(SDL_KeyboardEvent input); - +bool isAllowedInputTextKey(SDLKey key); }}//end namespace diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index a7e080f15..f99e6f8f3 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -983,7 +983,7 @@ bool isKeyPressed(SDLKey compareKey, SDL_KeyboardEvent input) { string pressKeyName = SDL_GetKeyName((SDLKey)c); if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] compareKey [%d - %s] pressed key [%d - %s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,compareKey,compareKeyName.c_str(),c,pressKeyName.c_str(),result); - //printf ("In [%s::%s Line: %d] compareKey [%d - %s] pressed key [%d - %s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,compareKey,compareKeyName.c_str(),c,pressKeyName.c_str(),result); + //printf ("In [%s::%s Line: %d] pressed key [%d - %s] input.keysym.unicode [%d] mod = %d\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str(),input.keysym.sym,input.keysym.unicode,input.keysym.mod); return result; } @@ -1011,9 +1011,65 @@ SDLKey extractKeyPressed(SDL_KeyboardEvent input) { string inputKeyName = SDL_GetKeyName(input.keysym.sym); if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] pressed key [%d - %s]\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str()); - //printf ("In [%s::%s Line: %d] pressed key [%d - %s] input [%d - %s] input.keysym.unicode [%d]\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str(),input.keysym.sym,inputKeyName.c_str(),input.keysym.unicode); + //printf ("In [%s::%s Line: %d] pressed key [%d - %s] input [%d - %s] input.keysym.unicode [%d] mod = %d\n",__FILE__,__FUNCTION__,__LINE__,c,pressKeyName.c_str(),input.keysym.sym,inputKeyName.c_str(),input.keysym.unicode,input.keysym.mod); return c; } +bool isAllowedInputTextKey(SDLKey key) { + bool result = ( + key != SDLK_DELETE && + key != SDLK_BACKSPACE && + key != SDLK_TAB && + key != SDLK_CLEAR && + key != SDLK_RETURN && + key != SDLK_PAUSE && + key != SDLK_UP && + key != SDLK_DOWN && + key != SDLK_RIGHT && + key != SDLK_LEFT && + key != SDLK_INSERT && + key != SDLK_HOME && + key != SDLK_END && + key != SDLK_PAGEUP && + key != SDLK_PAGEDOWN && + key != SDLK_F1 && + key != SDLK_F2 && + key != SDLK_F3 && + key != SDLK_F4 && + key != SDLK_F5 && + key != SDLK_F6 && + key != SDLK_F7 && + key != SDLK_F8 && + key != SDLK_F9 && + key != SDLK_F10 && + key != SDLK_F11 && + key != SDLK_F12 && + key != SDLK_F13 && + key != SDLK_F14 && + key != SDLK_F15 && + key != SDLK_NUMLOCK && + key != SDLK_CAPSLOCK && + key != SDLK_SCROLLOCK && + key != SDLK_RSHIFT && + key != SDLK_LSHIFT && + key != SDLK_RCTRL && + key != SDLK_LCTRL && + key != SDLK_RALT && + key != SDLK_LALT && + key != SDLK_RMETA && + key != SDLK_LMETA && + key != SDLK_LSUPER && + key != SDLK_RSUPER && + key != SDLK_MODE && + key != SDLK_HELP && + key != SDLK_PRINT && + key != SDLK_SYSREQ && + key != SDLK_BREAK && + key != SDLK_MENU && + key != SDLK_POWER); + + return result; +} + }}//end namespace