From 6582d0261e1d0084d6dc642b3d1aed06a87c2244 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 20 Oct 2011 18:34:19 -0400 Subject: [PATCH 1/2] Fix #82 It seems that silly Adam was storing a UINT scan code because MapVirtualKey wanted a UINT. However, WM_CHAR only has a BYTE scan code in its lParam. Therefore, we got garbage on repeated key events, which bungled up the key binding parser. --- Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp index 5cd7c8f7..2fb88b61 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputManager.cpp @@ -281,15 +281,14 @@ void plInputManager::HandleWin32ControlEvent(UINT message, WPARAM Wparam, LPARAM Wparam == KEY_TAB || Wparam == 0x0D) break; - UINT scan = Lparam >> 16; - scan = MapVirtualKeyEx(scan, MAPVK_VSC_TO_VK, nil); - if (scan == 0) scan = -1; + BYTE scan = Lparam >> 16; + UINT vkey = MapVirtualKey(scan, MAPVK_VSC_TO_VK); bExtended = Lparam >> 24 & 1; hsBool bRepeat = ((Lparam >> 29) & 0xf) != 0; bool down = !(Lparam >> 31); for (int i=0; iHandleKeyEvent( CHAR_MSG, (plKeyDef)scan, down, bRepeat, (wchar_t)Wparam ); + fInputDevices[i]->HandleKeyEvent( CHAR_MSG, (plKeyDef)vkey, down, bRepeat, (wchar_t)Wparam ); } break; case MOUSEWHEEL: From 6c4ec930b0383ae54446ec47f93d66b584a2f4c5 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 20 Oct 2011 19:20:03 -0400 Subject: [PATCH 2/2] Refresh CapsLock state on window restore This fixes an unreported bug where the avatar run-lock state can get confused after alt-tabbing. The other key states are too volatile to update... We never get the depressed events if they are pressed on window activation. --- .../Plasma/PubUtilLib/plInputCore/plInputDevice.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp index 05df204d..3e9152a6 100644 --- a/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp +++ b/Sources/Plasma/PubUtilLib/plInputCore/plInputDevice.cpp @@ -157,19 +157,16 @@ void plKeyboardDevice::HandleKeyEvent(plOSMsg message, plKeyDef key, bool bKeyDo if (key == KEY_SHIFT) { fShiftKeyDown = bKeyDown; -// return; } if (key == KEY_CTRL) { fCtrlKeyDown = bKeyDown; -// return; } if (key == KEY_CAPSLOCK) { - // Keyboards toggle the light on key-down, so I'm going with that. - if (bKeyDown && !bKeyRepeat) + if (!bKeyRepeat) { - fCapsLockLock = !fCapsLockLock; + fCapsLockLock = (GetKeyState(KEY_CAPSLOCK) & 1) == 1; plAvatarInputInterface::GetInstance()->ForceAlwaysRun(fCapsLockLock); } } @@ -190,7 +187,8 @@ void plKeyboardDevice::HandleWindowActivate(bool bActive, HWND hWnd) { if (bActive) { - fCtrlKeyDown = false; + // Refresh the caps lock state + HandleKeyEvent(KEYDOWN, KEY_CAPSLOCK, nil, false); } else {