Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@ void Menu::ProcessInputEventQueue()
logger::trace("Detected key code {} ({})", event.keyCode, key);
if (key == event.keyCode)
key = MapVirtualKeyEx(event.keyCode, MAPVK_VSC_TO_VK_EX, GetKeyboardLayout(0));

const bool wasCapturingHotkey = IsCapturingHotkeyInput();
const bool allowSetupCloseKey = wasCapturingHotkey && HomePageRenderer::ShouldShowFirstTimeSetup() &&
(key == VK_RETURN || key == VK_ESCAPE);
if (!event.IsPressed()) {
// Skip key release if it was used to close the first-time setup dialog
if (HomePageRenderer::ShouldSkipKeyRelease(key)) {
Expand Down Expand Up @@ -1028,7 +1032,13 @@ void Menu::ProcessInputEventQueue()
std::function<void()> action;
};
KeyAction keyActions[] = {
{ settings.ToggleKey, [this]() { if (!HomePageRenderer::ShouldShowFirstTimeSetup()) IsEnabled = !IsEnabled; } },
{ settings.ToggleKey, [this]() {
if (!HomePageRenderer::ShouldShowFirstTimeSetup()) {
IsEnabled = !IsEnabled;
if (IsEnabled)
ImGui::GetIO().ClearInputKeys(); // Prevent toggle key from remaining "held" in ImGui after open.
}
} },
{ settings.SkipCompilationKey, [this, shaderCache]() { if (!ShouldSwallowInput() && shaderCache->IsCompiling()) shaderCache->backgroundCompilation = true; } },
{ settings.EffectToggleKey, [shaderCache]() { shaderCache->SetEnabled(!shaderCache->IsEnabled()); } },
{ settings.ShaderBlockPrevKey, [this, shaderCache]() { if (settings.EnableShaderBlocking) shaderCache->IterateShaderBlock(); } },
Expand Down Expand Up @@ -1080,9 +1090,13 @@ void Menu::ProcessInputEventQueue()
bool isHotkey = ShouldSwallowInput() && std::any_of(std::begin(hotkeys), std::end(hotkeys),
[key](const auto* combo) { return InputCombo::MatchesKeyboardCombo(*combo, key); });

if (!isHotkey) {
// Always forward key-up events. Suppress key-down during active hotkeys,
// and during hotkey capture except setup close keys (Enter/Escape).
const bool isKeyDown = event.IsPressed();
const bool suppressForwarding = isKeyDown && (isHotkey || (wasCapturingHotkey && !allowSetupCloseKey));
if (!suppressForwarding) {
// DirectInput loses key-up events after alt-tab; validate against OS state.
bool pressed = event.IsPressed() && (GetAsyncKeyState(key) & Constants::KEY_PRESSED_MASK);
bool pressed = isKeyDown && (GetAsyncKeyState(key) & Constants::KEY_PRESSED_MASK);
io.AddKeyEvent(Util::Input::VirtualKeyToImGuiKey(key), pressed);

if (key == VK_LCONTROL || key == VK_RCONTROL)
Expand All @@ -1098,6 +1112,12 @@ void Menu::ProcessInputEventQueue()
_keyEventQueue.clear();
}

bool Menu::IsCapturingHotkeyInput() const
{
return settingToggleKey || settingSkipCompilationKey || settingsEffectsToggle ||
settingOverlayToggleKey || settingShaderBlockPrevKey || settingShaderBlockNextKey || settingWeatherEditorToggleKey;
}

void Menu::addToEventQueue(KeyEvent e)
{
std::unique_lock<std::shared_mutex> mutex(_inputEventMutex);
Expand Down
1 change: 1 addition & 0 deletions src/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,5 +501,6 @@ class Menu

void addToEventQueue(KeyEvent e);
void ProcessInputEventQueue();
bool IsCapturingHotkeyInput() const;
winrt::com_ptr<IDXGIAdapter3> dxgiAdapter3;
};
Loading