Work around Escape hotkey race with exit confirmation dialog

This commit is contained in:
mqudsi 2025-06-10 22:52:08 -05:00 committed by KeatonTheBot
parent 9f0a35ee9b
commit 878ea70aa9
2 changed files with 21 additions and 0 deletions

View file

@ -1152,6 +1152,24 @@ namespace Ryujinx.Ava
_dialogShown = true;
// The hard-coded hotkey mapped to exit is Escape, but it's also the same key
// that causes the dialog we launch to close (without doing anything). In release
// mode, a race is observed that between ShowExitPrompt() appearing on KeyDown
// and the ContentDialog we create seeing the key state before KeyUp. Merely waiting
// for the key to no longer be pressed appears to be insufficient.
// NB: Using _keyboardInterface.IsPressed(Key.Escape) does not currently work.
if (OperatingSystem.IsWindows())
{
while (GetAsyncKeyState(0x1B) != 0)
{
await Task.Delay(100);
}
}
else
{
await Task.Delay(250);
}
shouldExit = await ContentDialogHelper.CreateStopEmulationDialog();
_dialogShown = false;

View file

@ -111,5 +111,8 @@ namespace Ryujinx.Ava.UI.Helpers
[LibraryImport("user32.dll", SetLastError = true)]
public static partial IntPtr SetWindowLongPtrW(IntPtr hWnd, int nIndex, IntPtr value);
[LibraryImport("user32.dll", SetLastError = true)]
public static partial ushort GetAsyncKeyState(int nVirtKey);
}
}