@@ -387,6 +387,9 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
387
387
MSG msg{};
388
388
while (GetMessageW (&msg, nullptr , 0 , 0 ))
389
389
{
390
+ // This is `if (WM_KEYDOWN || WM_KEYUP || WM_SYSKEYDOWN || WM_SYSKEYUP)`.
391
+ // It really doesn't need to be written that obtuse, but it at
392
+ // least nicely mirrors our `keyDown = msg.message & 1` logic.
390
393
// FYI: For the key-down/up messages the lowest bit indicates if it's up.
391
394
if ((msg.message & ~1 ) == WM_KEYDOWN || (msg.message & ~1 ) == WM_SYSKEYDOWN)
392
395
{
@@ -401,7 +404,7 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
401
404
loggedInteraction = true ;
402
405
}
403
406
404
- const bool keyDown = msg.message & 1 ;
407
+ const bool keyDown = ( msg.message & 1 ) == 0 ;
405
408
if (
406
409
// GH#638: The Xaml input stack doesn't allow an application to suppress the "caret browsing"
407
410
// dialog experience triggered when you press F7. Official recommendation from the Xaml
@@ -448,15 +451,13 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
448
451
__assume (false );
449
452
}
450
453
451
- void WindowEmperor::_dispatchSpecialKey (MSG& msg) const
454
+ void WindowEmperor::_dispatchSpecialKey (const MSG& msg) const
452
455
{
453
- const auto hwnd = msg.hwnd ;
456
+ // Each CoreInput window is a child of our IslandWindow.
457
+ // We can figure out the IslandWindow HWND via GetAncestor().
458
+ const auto hwnd = GetAncestor (msg.hwnd , GA_ROOT);
454
459
AppHost* window = nullptr ;
455
460
456
- // Just in case someone has targed a specific HWND,
457
- // we'll try to dispatch it to the corresponding class.
458
- // Usually this will not find anything because under WinUI the hidden CoreInput
459
- // window is responsible for all input handling (for whatever reason).
460
461
for (const auto & h : _windows)
461
462
{
462
463
const auto w = h->GetWindow ();
@@ -467,6 +468,7 @@ void WindowEmperor::_dispatchSpecialKey(MSG& msg) const
467
468
}
468
469
}
469
470
471
+ // Fallback.
470
472
if (!window)
471
473
{
472
474
window = _mostRecentWindow ();
@@ -478,7 +480,7 @@ void WindowEmperor::_dispatchSpecialKey(MSG& msg) const
478
480
479
481
const auto vkey = gsl::narrow_cast<uint32_t >(msg.wParam );
480
482
const auto scanCode = gsl::narrow_cast<uint8_t >(msg.lParam >> 16 );
481
- const bool keyDown = msg.message & 1 ;
483
+ const bool keyDown = ( msg.message & 1 ) == 0 ;
482
484
window->OnDirectKeyEvent (vkey, scanCode, keyDown);
483
485
}
484
486
0 commit comments