Bug fix for windows Qt GUI left/right modifier key determination.

This commit is contained in:
mjbudd77 2022-03-02 21:42:51 -05:00
parent 35028fc3e5
commit ddaa20f171
1 changed files with 94 additions and 0 deletions

View File

@ -35,6 +35,7 @@ static uint32_t ShiftKeyCodeR = VK_RSHIFT;
static uint32_t CtrlKeyCodeR = VK_RCONTROL; static uint32_t CtrlKeyCodeR = VK_RCONTROL;
static uint32_t AltKeyCodeR = VK_RMENU; static uint32_t AltKeyCodeR = VK_RMENU;
static uint32_t MetaKeyCodeR = VK_RWIN; static uint32_t MetaKeyCodeR = VK_RWIN;
static BYTE keyBuf[256];
#elif defined(__linux__) #elif defined(__linux__)
@ -133,6 +134,16 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
s = SDL_SCANCODE_PAGEDOWN; s = SDL_SCANCODE_PAGEDOWN;
break; break;
case Key_Shift: case Key_Shift:
#if defined(WIN32)
if ( keyBuf[ShiftKeyCodeR] & 0x80 )
{
s = SDL_SCANCODE_RSHIFT;
}
else
{
s = SDL_SCANCODE_LSHIFT;
}
#else
if ( nativeVirtualKey == ShiftKeyCodeR ) if ( nativeVirtualKey == ShiftKeyCodeR )
{ {
s = SDL_SCANCODE_RSHIFT; s = SDL_SCANCODE_RSHIFT;
@ -141,6 +152,7 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDL_SCANCODE_LSHIFT; s = SDL_SCANCODE_LSHIFT;
} }
#endif
break; break;
case Key_Control: case Key_Control:
#ifdef __APPLE__ #ifdef __APPLE__
@ -152,6 +164,15 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDL_SCANCODE_LGUI; s = SDL_SCANCODE_LGUI;
} }
#elif defined(WIN32)
if ( keyBuf[CtrlKeyCodeR] & 0x80 )
{
s = SDL_SCANCODE_RCTRL;
}
else
{
s = SDL_SCANCODE_LCTRL;
}
#else #else
if ( nativeVirtualKey == CtrlKeyCodeR ) if ( nativeVirtualKey == CtrlKeyCodeR )
{ {
@ -173,6 +194,15 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDL_SCANCODE_LCTRL; s = SDL_SCANCODE_LCTRL;
} }
#elif defined(WIN32)
if ( keyBuf[MetaKeyCodeR] & 0x80 )
{
s = SDL_SCANCODE_RGUI;
}
else
{
s = SDL_SCANCODE_LGUI;
}
#else #else
if ( nativeVirtualKey == MetaKeyCodeR ) if ( nativeVirtualKey == MetaKeyCodeR )
{ {
@ -185,6 +215,16 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
#endif #endif
break; break;
case Key_Alt: case Key_Alt:
#if defined(WIN32)
if ( keyBuf[AltKeyCodeR] & 0x80 )
{
s = SDL_SCANCODE_RALT;
}
else
{
s = SDL_SCANCODE_LALT;
}
#else
if ( nativeVirtualKey == AltKeyCodeR ) if ( nativeVirtualKey == AltKeyCodeR )
{ {
s = SDL_SCANCODE_RALT; s = SDL_SCANCODE_RALT;
@ -193,6 +233,7 @@ SDL_Scancode convQtKey2SDLScanCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDL_SCANCODE_LALT; s = SDL_SCANCODE_LALT;
} }
#endif
break; break;
case Key_CapsLock: case Key_CapsLock:
s = SDL_SCANCODE_CAPSLOCK; s = SDL_SCANCODE_CAPSLOCK;
@ -655,6 +696,25 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
s = SDLK_PAGEDOWN; s = SDLK_PAGEDOWN;
break; break;
case Key_Shift: case Key_Shift:
#if defined(WIN32)
if ( keyBuf[ShiftKeyCodeR] & 0x80)
{
s = SDLK_RSHIFT;
}
else
{
s = SDLK_LSHIFT;
}
#elif defined(WIN32)
if ( keyBuf[ShiftKeyCodeR] & 0x80 )
{
s = SDLK_RSHIFT;
}
else
{
s = SDLK_LSHIFT;
}
#else
if ( nativeVirtualKey == ShiftKeyCodeR ) if ( nativeVirtualKey == ShiftKeyCodeR )
{ {
s = SDLK_RSHIFT; s = SDLK_RSHIFT;
@ -663,6 +723,7 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDLK_LSHIFT; s = SDLK_LSHIFT;
} }
#endif
break; break;
case Key_Control: case Key_Control:
#ifdef __APPLE__ #ifdef __APPLE__
@ -674,6 +735,15 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDLK_LGUI; s = SDLK_LGUI;
} }
#elif defined(WIN32)
if ( keyBuf[CtrlKeyCodeR] & 0x80 )
{
s = SDLK_RCTRL;
}
else
{
s = SDLK_LCTRL;
}
#else #else
if ( nativeVirtualKey == CtrlKeyCodeR ) if ( nativeVirtualKey == CtrlKeyCodeR )
{ {
@ -695,6 +765,15 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDLK_LCTRL; s = SDLK_LCTRL;
} }
#elif defined(WIN32)
if ( keyBuf[MetaKeyCodeR] & 0x80 )
{
s = SDLK_RGUI;
}
else
{
s = SDLK_LGUI;
}
#else #else
if ( nativeVirtualKey == MetaKeyCodeR ) if ( nativeVirtualKey == MetaKeyCodeR )
{ {
@ -707,6 +786,16 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
#endif #endif
break; break;
case Key_Alt: case Key_Alt:
#if defined(WIN32)
if ( keyBuf[AltKeyCodeR] & 0x80 )
{
s = SDLK_RALT;
}
else
{
s = SDLK_LALT;
}
#else
if ( nativeVirtualKey == AltKeyCodeR ) if ( nativeVirtualKey == AltKeyCodeR )
{ {
s = SDLK_RALT; s = SDLK_RALT;
@ -715,6 +804,7 @@ SDL_Keycode convQtKey2SDLKeyCode(Qt::Key q, uint32_t nativeVirtualKey)
{ {
s = SDLK_LALT; s = SDLK_LALT;
} }
#endif
break; break;
case Key_CapsLock: case Key_CapsLock:
s = SDLK_CAPSLOCK; s = SDLK_CAPSLOCK;
@ -1220,6 +1310,10 @@ int pushKeyEvent(QKeyEvent *event, int pressDown)
sdlev.key.state = SDL_RELEASED; sdlev.key.state = SDL_RELEASED;
} }
#ifdef WIN32
GetKeyboardState( keyBuf );
#endif
vkey = event->nativeVirtualKey(); vkey = event->nativeVirtualKey();
sdlev.key.keysym.sym = convQtKey2SDLKeyCode((Qt::Key)event->key(), vkey); sdlev.key.keysym.sym = convQtKey2SDLKeyCode((Qt::Key)event->key(), vkey);