diff --git a/Windows/RawInput.cpp b/Windows/RawInput.cpp index c8d97fea07..d7fc70f008 100644 --- a/Windows/RawInput.cpp +++ b/Windows/RawInput.cpp @@ -21,6 +21,7 @@ #include "input/input_state.h" #include "Windows/RawInput.h" #include "Windows/KeyboardDevice.h" +#include "Windows/WndMainWindow.h" #include "Windows/WindowsHost.h" #include "Common/CommonFuncs.h" #include "Core/Config.h" @@ -54,6 +55,7 @@ namespace WindowsRawInput { static std::set keyboardKeysDown; static void *rawInputBuffer; static size_t rawInputBufferSize; + static bool menuActive; void Init() { RAWINPUTDEVICE dev[3]; @@ -76,6 +78,16 @@ namespace WindowsRawInput { } } + bool UpdateMenuActive() { + MENUBARINFO info; + memset(&info, 0, sizeof(info)); + info.cbSize = sizeof(info); + if (GetMenuBarInfo(MainWindow::GetHWND(), OBJID_MENU, 0, &info) != 0) { + menuActive = info.fBarFocused != FALSE; + } + return menuActive; + } + static int GetTrueVKey(const RAWKEYBOARD &kb) { switch (kb.VKey) { case VK_SHIFT: @@ -99,6 +111,11 @@ namespace WindowsRawInput { } void ProcessKeyboard(RAWINPUT *raw, bool foreground) { + if (menuActive && UpdateMenuActive()) { + // Ignore keyboard input while a menu is active, it's probably interacting with the menu. + return; + } + KeyInput key; key.deviceId = DEVICE_ID_KEYBOARD; @@ -125,6 +142,11 @@ namespace WindowsRawInput { } void ProcessMouse(RAWINPUT *raw, bool foreground) { + if (menuActive && UpdateMenuActive()) { + // Ignore mouse input while a menu is active, it's probably interacting with the menu. + return; + } + KeyInput key; key.deviceId = DEVICE_ID_MOUSE; @@ -192,6 +214,10 @@ namespace WindowsRawInput { } } + void NotifyMenu() { + UpdateMenuActive(); + } + void Shutdown() { if (rawInputBuffer) { free(rawInputBuffer); diff --git a/Windows/RawInput.h b/Windows/RawInput.h index 72ec42078e..c662ccd2d2 100644 --- a/Windows/RawInput.h +++ b/Windows/RawInput.h @@ -21,5 +21,6 @@ namespace WindowsRawInput { void Init(); LRESULT Process(HWND hWnd, WPARAM wParam, LPARAM lParam); void LoseFocus(); + void NotifyMenu(); void Shutdown(); }; \ No newline at end of file diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 67d1f60eb8..aff5e3e8a8 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -1584,6 +1584,7 @@ namespace MainWindow // Unfortunately, accelerate keys (hotkeys) shares the same enabled/disabled states // with corresponding menu items. UpdateMenus(); + WindowsRawInput::NotifyMenu(); break; // Turn off the screensaver.