Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt-F4 keyboard shortcut not working with XAML island #2408

Closed
vsfeedback opened this issue May 7, 2020 · 11 comments
Closed

Alt-F4 keyboard shortcut not working with XAML island #2408

vsfeedback opened this issue May 7, 2020 · 11 comments
Labels
needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) team-Reach Issue for the Reach team

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


I'm implementing a native desktop app using winrt. I'm using Visual Studio 2019 16.5.4, Windows 1909 (Build 18363.778)

Pressing Alt F4 is not working to close the application window when the application is hosting content with XAML Island and
the keyboard focus has been moved to a XAML control.

Can be reproduced with the following sample:

https://github.com/microsoft/Xaml-Islands-Samples/tree/master/Standalone_Samples/CppWinRT_Basic_Win32App

Steps to reproduce

  • Start the application

  • Click on the "Hello from Win32" content

  • Press Alt F4, the application close OK.

  • Start the application gain

  • Click on the "Hello from XAML island"

  • Press Alt FT, the application does not close.

I did not found any reference on how to handle the keyboard navigation, including handling PreTranslateMessage (using
IDesktopWindowXamlSourceNative2) to make the standard Windows behavior to work as expected.

Thanks for your time,
Pascal


Original Comments

Visual Studio Feedback System on 5/6/2020, 07:59 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label May 7, 2020
@StephenLPeters StephenLPeters added needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) team-Reach Issue for the Reach team labels May 28, 2020
@Austin-Lamb
Copy link

Thanks for reporting this - we are investigating, and think we may have a possible fix, but we'll do more testing.

@Austin-Lamb Austin-Lamb removed the needs-triage Issue needs to be triaged by the area owners label Aug 11, 2020
@sylveon
Copy link
Contributor

sylveon commented Oct 20, 2020

Can reproduce this

@crutkas
Copy link
Member

crutkas commented Oct 20, 2020

affecting powertoys.

@sylveon
Copy link
Contributor

sylveon commented Oct 20, 2020

My crude workaround was putting this before PreTranslateMessage

// prevent XAML islands from capturing ALT-F4 because of
// https://github.com/microsoft/microsoft-ui-xaml/issues/2408
if (msg.message == WM_SYSKEYDOWN && msg.wParam == VK_F4) [[unlikely]]
{
	SendMessage(GetAncestor(msg.hwnd, GA_ROOT), msg.message, msg.wParam, msg.lParam);
	continue;
}

to send back the message to my hosting window.

@crutkas
Copy link
Member

crutkas commented Oct 21, 2020

@sylveon that is the c++ workaround, now to see what the WPF workaround is :)

@crutkas
Copy link
Member

crutkas commented Oct 21, 2020

#2481 looks to be the same issue

sylveon added a commit to TranslucentTB/TranslucentTB that referenced this issue Oct 24, 2020
@sylveon
Copy link
Contributor

sylveon commented Nov 1, 2020

If you do any processing of ALT+some key it seems that you have to the same. I just needed some special alt+space processing, and had to replace that if by if (msg.message == WM_SYSKEYDOWN && (msg.wParam == VK_F4 || msg.wParam == VK_SPACE)) to get things to work.

As for WPF, you need to use ComponentDispatcher.ThreadFilterMessage @crutkas. I haven't personally tested it, but it's how the WPF XamlHost does its PreTranslateMessage processing, so it's your best chance.

@Jay-o-Way
Copy link
Contributor

Is there an update for this issue?

Thanks for reporting this - we are investigating, and think we may have a possible fix, but we'll do more testing.

@Austin-Lamb That's one year ago now.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@sylveon
Copy link
Contributor

sylveon commented Jul 29, 2023

Still a problem

@JesseCol
Copy link

JesseCol commented Sep 1, 2023

Hi there -- if you're interested in moving to WinAppSDK / WinUI3, the version 1.4 stable release now includes similar islands APIs. We've got a sample in progress here: microsoft/WindowsAppSDK-Samples#307 . I've validated that ALT+F4 works fine in that sample. (Note though that the sample contains a WebView2, and ALT+F4 does not automatically work when keyboard focus is in the WebView2, sadly. (see #8058) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) team-Reach Issue for the Reach team
Projects
None yet
Development

No branches or pull requests

8 participants