diff --git a/include/osgViewer/api/Win32/GraphicsWindowWin32 b/include/osgViewer/api/Win32/GraphicsWindowWin32 index a8d925c5e..e359bd940 100644 --- a/include/osgViewer/api/Win32/GraphicsWindowWin32 +++ b/include/osgViewer/api/Win32/GraphicsWindowWin32 @@ -135,8 +135,7 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, p bool setPixelFormat(); - // return true if it handled the key, otherwise return false so that we know it is WM_CHAR job to handle it - bool adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask ); + void adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask ); void transformMouseXY(float& x, float& y); @@ -180,9 +179,6 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, p std::map _mouseCursorMap; std::map _keyMap; - bool _keypresshandled; - int _lastkeysymbol; - std::map _scancode_unicode_Map; bool _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues; }; diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index d25331732..160c9fc89 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -2212,7 +2212,7 @@ void GraphicsWindowWin32::setSyncToVBlank( bool on ) #endif } -bool GraphicsWindowWin32::adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask ) +void GraphicsWindowWin32::adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol, unsigned int& modifierMask ) { modifierMask = 0; @@ -2224,7 +2224,7 @@ bool GraphicsWindowWin32::adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol if (virtualKey==0 || !::GetKeyboardState(keyState)) { keySymbol = 0; - return true; + return; } switch (virtualKey) @@ -2280,15 +2280,10 @@ bool GraphicsWindowWin32::adaptKey( WPARAM wParam, LPARAM lParam, int& keySymbol } else if ((keySymbol & 0xff00)==0) { - // store the raw key so to be used later in WM_CHAR event - keySymbol = ::MapVirtualKeyEx(HIWORD(lParam), 2, ::GetKeyboardLayout(0)); - - // might be an unicode key or dead key so need to be handled by WM_CHAR - return false; + char asciiKey[2]; + int numChars = ::ToAscii(wParam, (lParam>>16)&0xff, keyState, reinterpret_cast(asciiKey), 0); + if (numChars>0) keySymbol = asciiKey[0]; } - - // it was a special key so event is handled - return true; } void GraphicsWindowWin32::transformMouseXY( float& x, float& y ) @@ -2439,36 +2434,6 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W } } break; - ///////////////// - case WM_CHAR : - ///////////////// - { - // if event was not handled by WM_KEYDOWN then we take care of it here - // this method gives directly the utf16 char back so just need to add it as it is - if(!_keypresshandled) - { - // first check if key is already registered on the map - std::map::iterator it = _scancode_unicode_Map.find(_lastkeysymbol); - if(it != _scancode_unicode_Map.end()) - { - // map already exist -> key already pressed and not yet released - if((it->second != -1) && (it->second != wParam)) - { - // was a different char stored - probably a dead key combinaison - // -> we need to release it first - _keyMap[it->second] = false; - getEventQueue()->keyRelease(it->second, eventTime); - } - } - - // store the raw key in map so that we know what to release later in WM_KEYUP event - _scancode_unicode_Map[_lastkeysymbol] = wParam; - - _keyMap[wParam] = true; - getEventQueue()->keyPress(wParam, eventTime); - } - } - break; //////////////////// case WM_KEYDOWN : @@ -2478,19 +2443,10 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W { int keySymbol = 0; unsigned int modifierMask = 0; - if(adaptKey(wParam, lParam, keySymbol, modifierMask)) - { - // was a special key, we handled it - _keypresshandled = true; - _keyMap[keySymbol] = true; - getEventQueue()->keyPress(keySymbol, eventTime); - } - else - { - // was no special key, let WM_CHAR handle it - _keypresshandled = false; - _lastkeysymbol = keySymbol; - } + adaptKey(wParam, lParam, keySymbol, modifierMask); + _keyMap[keySymbol] = true; + //getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask); + getEventQueue()->keyPress(keySymbol, eventTime); } break; @@ -2502,23 +2458,10 @@ LRESULT GraphicsWindowWin32::handleNativeWindowingEvent( HWND hwnd, UINT uMsg, W { int keySymbol = 0; unsigned int modifierMask = 0; - if(!adaptKey(wParam, lParam, keySymbol, modifierMask)) - { - // was not a special key - this mean we need to release the unicode key - // -> fetch it from the map - std::map::iterator it = _scancode_unicode_Map.find(keySymbol); - if(it != _scancode_unicode_Map.end()) - { - keySymbol = it->second; - it->second = -1; // clean the release key from the map - } - } - - if(keySymbol >= 0) - { - _keyMap[keySymbol] = false; - getEventQueue()->keyRelease(keySymbol, eventTime); - } + adaptKey(wParam, lParam, keySymbol, modifierMask); + _keyMap[keySymbol] = false; + //getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask); + getEventQueue()->keyRelease(keySymbol, eventTime); } break;