Extend code that detects whether a key was consumed by the GUI (Fixes #4016)

pull/303/head
scrawl 7 years ago
parent 2c4b0cc408
commit 9ed1b16553

@ -2000,7 +2000,30 @@ namespace MWGui
bool WindowManager::injectKeyPress(MyGUI::KeyCode key, unsigned int text)
{
if (!mKeyboardNavigation->injectKeyPress(key, text))
return MyGUI::InputManager::getInstance().injectKeyPress(key, text);
{
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
bool widgetActive = MyGUI::InputManager::getInstance().injectKeyPress(key, text);
if (!widgetActive || !focus)
return false;
// FIXME: MyGUI doesn't allow widgets to state if a given key was actually used, so make a guess
if (focus->getTypeName().find("Button") != std::string::npos)
{
switch (key.getValue())
{
case MyGUI::KeyCode::ArrowDown:
case MyGUI::KeyCode::ArrowUp:
case MyGUI::KeyCode::ArrowLeft:
case MyGUI::KeyCode::ArrowRight:
case MyGUI::KeyCode::Return:
case MyGUI::KeyCode::NumpadEnter:
case MyGUI::KeyCode::Space:
return true;
default:
return false;
}
}
return false;
}
else
return true;
}

@ -674,10 +674,11 @@ namespace MWInput
bool consumed = false;
if (kc != OIS::KC_UNASSIGNED)
{
consumed = SDL_IsTextInputActive() &&
( !(SDLK_SCANCODE_MASK & arg.keysym.sym) && std::isprint(arg.keysym.sym)); // Little trick to check if key is printable
bool guiFocus = MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Enum(kc), 0);
setPlayerControlsEnabled(!guiFocus);
consumed = MWBase::Environment::get().getWindowManager()->injectKeyPress(MyGUI::KeyCode::Enum(kc), 0);
if (SDL_IsTextInputActive() && // Little trick to check if key is printable
( !(SDLK_SCANCODE_MASK & arg.keysym.sym) && std::isprint(arg.keysym.sym)))
consumed = true;
setPlayerControlsEnabled(!consumed);
}
if (arg.repeat)
return;

Loading…
Cancel
Save