windows: Ignore key/mouse input while menu focused.

This prevents arrow and shortcut keys from being considered inputs to the
game or UI.
This commit is contained in:
Unknown W. Brackets 2014-01-20 00:57:20 -08:00
parent 0e286d6603
commit 83eb5f05bc
3 changed files with 28 additions and 0 deletions

View file

@ -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<int> 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);

View file

@ -21,5 +21,6 @@ namespace WindowsRawInput {
void Init();
LRESULT Process(HWND hWnd, WPARAM wParam, LPARAM lParam);
void LoseFocus();
void NotifyMenu();
void Shutdown();
};

View file

@ -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.