ImguiSystem: reset keydown state properly once window closes

In commit 1fd4c25cd0188f96c7d1fe7b0a8b072763eed032, an attempt was made to fix this by calling the message handler with WM_NULL, but WM_KILLFOCUS should've been passed instead, as Dear ImGui clears the keydown state with this message. WM_NULL does nothing.
This commit is contained in:
Kawe Mazidjatari 2024-11-28 00:26:15 +01:00
parent c8e8bea154
commit 77851d9ad7
3 changed files with 8 additions and 10 deletions

View File

@ -83,16 +83,14 @@ LRESULT CGame::ImguiWindowProc(HWND hWnd, UINT& uMsg, WPARAM wParam, LPARAM lPar
}//////////////////////////////////////////////////////////////////////////////
else
{
if (g_bBlockInput)
if (g_bBlockInput.exchange(false))
{
// Dry run with null msg to clear the event queue, we have to do this as
// the menu's can be closed while still holding down a key. That key will
// remain in the event queue so the next time a window is opened, that
// key will be spammed until that particular key msg is sent here again.
hr = ImguiSystem()->MessageHandler(hWnd, WM_NULL, wParam, lParam);
// Dry run with kill focus msg to clear the keydown state, we have to do
// this as the menu's can be closed while still holding down a key. That
// key will remain pressed down so the next time a window is opened that
// key will be spammed, until that particular key msg is sent here again.
hr = ImguiSystem()->MessageHandler(hWnd, WM_KILLFOCUS, wParam, lParam);
}
g_bBlockInput = false;
}
return hr;

View File

@ -19,7 +19,7 @@ static IShowCursor g_oShowCursor = nullptr;
///////////////////////////////////////////////////////////////////////////////
static POINT g_pLastCursorPos { 0 };
extern BOOL g_bBlockInput = false;
extern std::atomic_bool g_bBlockInput = false;
//#############################################################################
// INITIALIZATION

View File

@ -7,6 +7,6 @@ void Input_Shutdown();
/////////////////////////////////////////////////////////////////////////////
// Globals
extern BOOL g_bBlockInput;
extern std::atomic_bool g_bBlockInput;
/////////////////////////////////////////////////////////////////////////////