From 46b1b818ccb5d6f018e4bd5015a131b7a4ece300 Mon Sep 17 00:00:00 2001 From: beaglejoe Date: Mon, 4 Apr 2016 03:40:56 +0000 Subject: [PATCH] Fix for [#950] git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6395 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: a78c3403d861fb0be0fb4d80bd46be335334ed75 Former-commit-id: 6a977646425d8b62dcfa53b2ff7430b3cb36c1a3 --- src/libs/tgf/eventloop.cpp | 35 +++++++++++++++++++++++++---- src/libs/tgfclient/guieventloop.cpp | 31 ++++++------------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/libs/tgf/eventloop.cpp b/src/libs/tgf/eventloop.cpp index aa62126c0..38f00dafe 100644 --- a/src/libs/tgf/eventloop.cpp +++ b/src/libs/tgf/eventloop.cpp @@ -58,10 +58,8 @@ private: // Private data members. //! Initialization flag for the underlying software layers. static bool _bInitialized; -#if SDL_MAJOR_VERSION < 2 //! Unicode for each typed SDL key sym + modifier std::map _mapUnicodes; -#endif }; GfEventLoop::Private::Private() @@ -118,11 +116,40 @@ int GfEventLoop::Private::translateKeySym(int code, int modifier, int unicode) // Done. return keyUnicode; #else + int keyUnicode = code; //default to returning code + // Make the Numpad key behave like the regular key if(SDLK_KP_ENTER == code) - code = SDLK_RETURN; + keyUnicode = SDLK_RETURN; - return code; + else + { + const Uint32 keyId = ((Uint32)code & GF_MAX_KEYCODE) | (((Uint32)modifier) << 9); + + // If unicode - add to the map... + if(unicode) + { + // Truncate unicodes above GF_MAX_KEYCODE (no need for more). + keyUnicode = (unsigned short)(unicode & GF_MAX_KEYCODE); + _mapUnicodes[keyId] = (unsigned short)keyUnicode; + GfLogDebug("translateKeySym(c=%X, m=%X, u=%X) : '%c', id=%X, ucode=%X (nk=%d)\n", + code, modifier, unicode, // Truncate high bits for MSVC 2010 bugs. + (keyUnicode > 0 && keyUnicode < 128 && isprint(keyUnicode & 0x7F)) + ? (char)(keyUnicode & 0x7F) : ' ', + keyId, keyUnicode, _mapUnicodes.size()); + } + else + { + // Search it in our unicode map. + const std::map::const_iterator itUnicode = _mapUnicodes.find(keyId); + if (itUnicode != _mapUnicodes.end()) + { + keyUnicode = (*itUnicode).second; + } + } + } + + return keyUnicode; #endif } diff --git a/src/libs/tgfclient/guieventloop.cpp b/src/libs/tgfclient/guieventloop.cpp index ec3abbe0e..af9af15ac 100644 --- a/src/libs/tgfclient/guieventloop.cpp +++ b/src/libs/tgfclient/guieventloop.cpp @@ -136,6 +136,7 @@ void GfuiEventLoop::operator()() #if SDL_MAJOR_VERSION >= 2 static int unicode = 0; static SDL_Keymod modifier = KMOD_NONE; + static SDL_Keycode keysym = SDLK_UNKNOWN; #endif // Check for events. @@ -165,12 +166,11 @@ void GfuiEventLoop::operator()() { injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,0); } -#if 0 else { - printf("SDL_KEYDOWN: %c\r\n",(char)event.key.keysym.sym); + //GfLogDebug("SDL_KEYDOWN: %c\r\n",(char)event.key.keysym.sym); + keysym = event.key.keysym.sym; } -#endif #endif break; @@ -178,8 +178,8 @@ void GfuiEventLoop::operator()() case SDL_TEXTINPUT: unicode = (int)(event.text.text[0]); modifier = SDL_GetModState(); - injectKeyboardEvent(unicode,modifier, 0,0); - //printf("SDL_TEXTINPUT: %c %X\r\n",(char)unicode,modifier); + injectKeyboardEvent(keysym, modifier, 0, unicode); + //GfLogDebug("SDL_TEXTINPUT: %c %X\r\n",(char)unicode,modifier); break; #endif @@ -187,25 +187,8 @@ void GfuiEventLoop::operator()() #if SDL_MAJOR_VERSION < 2 injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,event.key.keysym.unicode); #else - if((event.key.keysym.sym & SDLK_SCANCODE_MASK) == SDLK_SCANCODE_MASK) - { - injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0); - } - else if(false == isprint(event.key.keysym.sym)) - { - injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0); - } - else if((event.key.keysym.mod & KMOD_CTRL) - ||(event.key.keysym.mod & KMOD_ALT) - ||(event.key.keysym.mod & KMOD_GUI)) - { - injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0); - } - else - { - injectKeyboardEvent(unicode, event.key.keysym.mod, 1,0); - //printf("SDL_KEYUP: %c unicode = %c\r\n",(char)event.key.keysym.sym,unicode); - } + injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0); + //GfLogDebug("SDL_KEYUP: %c\r\n",(char)event.key.keysym.sym); #endif break;