diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 17251aff5..763e75ae7 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -413,6 +413,7 @@ namespace MWInput } #endif */ + MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(arg.keysym.sym), text); return true; diff --git a/apps/openmw/mwinput/sdlinputwrapper.cpp b/apps/openmw/mwinput/sdlinputwrapper.cpp index 32f453b0f..56b3568f5 100644 --- a/apps/openmw/mwinput/sdlinputwrapper.cpp +++ b/apps/openmw/mwinput/sdlinputwrapper.cpp @@ -27,8 +27,10 @@ namespace MWInput MWSDLInputWrapper::~MWSDLInputWrapper() { - SDL_DestroyWindow(mSDLWindow); + if(mSDLWindow != NULL) + SDL_DestroyWindow(mSDLWindow); mSDLWindow = NULL; + SDL_StopTextInput(); SDL_Quit(); } @@ -52,6 +54,8 @@ namespace MWInput if(mSDLWindow == NULL) return false; + SDL_StartTextInput(); + #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX //linux-specific event-handling fixups SDL_SysWMinfo wm_info; @@ -119,7 +123,7 @@ namespace MWInput break; case SDL_KEYDOWN: - mKeyboardListener->keyPressed(evt.key); + _handleKeyPress(evt.key); break; case SDL_KEYUP: mKeyboardListener->keyReleased(evt.key); @@ -228,4 +232,23 @@ namespace MWInput warpMouse(width / 2, height / 2); } } + + void MWSDLInputWrapper::_handleKeyPress(SDL_KeyboardEvent &evt) + { + //SDL keyboard events are followed by the actual text those keys would generate + //to account for languages that require multiple keystrokes to produce a key. + //Look for an event immediately following ours, assuming each key produces exactly + //one character. + + //TODO: This won't work for multibyte characters, but MyGUI is the only consumer + //of these, does it even support multibyte characters? + + SDL_Event text_evts[1]; + if(SDL_PeepEvents(text_evts, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT) != 0) + { + evt.keysym.unicode = text_evts[0].text.text[0]; + } + + mKeyboardListener->keyPressed(evt); + } } diff --git a/apps/openmw/mwinput/sdlinputwrapper.hpp b/apps/openmw/mwinput/sdlinputwrapper.hpp index c2770ae7e..6377d0bcf 100644 --- a/apps/openmw/mwinput/sdlinputwrapper.hpp +++ b/apps/openmw/mwinput/sdlinputwrapper.hpp @@ -30,6 +30,8 @@ namespace MWInput bool _handleWarpMotion(const SDL_MouseMotionEvent& evt); void _wrapMousePointer(const SDL_MouseMotionEvent &evt); + void _handleKeyPress(SDL_KeyboardEvent& evt); + bool _start(); ICS::MWSDLMouseListener* mMouseListener;