MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
439 stars 51 forks source link

System menu doesn't open when "Alt + Space" is pressed while after focusing on WebVew2 control #3840

Open harunurhan opened 11 months ago

harunurhan commented 11 months ago

Description

System menu doesn't open when "Alt + Space" is pressed if user clicks on the WebView2 control.

Version SDK: 1.0.1462.37 Runtime: 117.0.2045.47 Framework: WinForms OS: Win10

Regression Was this working before but has regressed? NO If yes, what version did this last work on?

Repro Steps

Screenshots

AB#43314365

Additional context

champnic commented 10 months ago

Thanks for the bug report @harunurhan and sorry you're hitting this. This is a known issue, so I've linked this to the bug on our backlog.

victorhuangwq commented 10 months ago

In the meantime, @bradp0721 suggested a workaround for this issue, by adding the following conditional to the AcceleratorKeyPressed event handler, enabling the system menu to be shown upon Alt + Space

if (GetKeyState(VK_MENU) < 0 && key == VK_SPACE)
{
    HMENU menu = ::GetSystemMenu(m_appWindow->GetMainWindow(), FALSE);
    POINT pt = { 0, 0 };
    ClientToScreen(m_appWindow->GetMainWindow(), &pt);
    const int command = ::TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
    pt.x, pt.y, 0, m_appWindow->GetMainWindow(), nullptr);
    if (command)
    {
        ::SendMessage(m_appWindow->GetMainWindow(), WM_SYSCOMMAND, static_cast<WPARAM>(command), 0);
    }
    CHECK_FAILURE(args->put_Handled(TRUE));
}

Could you let us know if this works for you?

harunurhan commented 10 months ago

@victorhuangwq, thanks adapted this to C# and used KeyDown on WebView2 control for WinForms, it seems to work.

harry330 commented 3 months ago

In the meantime, @bradp0721 suggested a workaround for this issue, by adding the following conditional to the AcceleratorKeyPressed event handler, enabling the system menu to be shown upon Alt + Space

if (GetKeyState(VK_MENU) < 0 && key == VK_SPACE)
{
    HMENU menu = ::GetSystemMenu(m_appWindow->GetMainWindow(), FALSE);
    POINT pt = { 0, 0 };
    ClientToScreen(m_appWindow->GetMainWindow(), &pt);
    const int command = ::TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
    pt.x, pt.y, 0, m_appWindow->GetMainWindow(), nullptr);
    if (command)
    {
        ::SendMessage(m_appWindow->GetMainWindow(), WM_SYSCOMMAND, static_cast<WPARAM>(command), 0);
    }
    CHECK_FAILURE(args->put_Handled(TRUE));
}

Could you let us know if this works for you?

I was noticed that WPF does not have AcceleratorKeyPressed event, is there any workaround for WPF?

champnic commented 3 months ago

@harry330 on WPF you'll use "OnKeyDown" instead: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.wpf.webview2?view=webview2-dotnet-1.0.2478.35#remarks