MicrosoftEdge / MicrosoftEdge/WebView2Feedback
ToolStripMenuItem ShortcutKeys do not work inside the browser
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Description
When you assign ShortcutKeys to a ToolStripMenuItem on a MenuStrip on a form and place the WebView2 in the same form and focus the browser, then the shortcuts do not work.
Version
SDK: 1.0.865-prerelease
Runtime: Stable 90.0.818.51
Framework: WinForms
OS: Win10 Version 20H2
Repro Steps
We use the following code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Web.WebView2.WinForms;
namespace WebView2BugShortCutKeys
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(CreateTestForm());
}
public static Form CreateTestForm()
{
var form = new Form
{
Size = new Size(1280, 1024)
};
var menuStrip = new MenuStrip
{
Dock = DockStyle.Top
};
var definitionMenuItem = new ToolStripMenuItem("Go to definition", null)
{
ShortcutKeys = Keys.Control | Keys.D,
ShowShortcutKeys = true,
ShortcutKeyDisplayString = "Ctrl+D"
};
definitionMenuItem.Click += (sender, e) =>
{
};
var settingsMenuItem = new ToolStripMenuItem("Settings", null, definitionMenuItem);
menuStrip.Items.Add(settingsMenuItem);
var webView2 = new WebView2
{
Dock = DockStyle.Fill,
Source = new Uri(@"https://www.google.com")
};
var textBox = new TextBox
{
Dock = DockStyle.Bottom
};
form.Controls.Add(menuStrip);
form.Controls.Add(webView2);
form.Controls.Add(textBox);
return form;
}
}
}
When you put a breakpoint in definitionMenuItem.Click you will see the following:
- When the textbox is focused and you press Ctrl+D, the breakpoint will be hit.
- When the browser is focused and you press Ctrl+D, the breakpoint will not be hit.
We expect WebView2 to fully cooperate with the rest of the form, so it should respect the ShortcutKeys of the ToolStripMenuItem objects.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CreateTestForm reproduction and compare shortcut behavior when the TextBox and WebView2 have focus. Use the ToolStripMenuItem.Click breakpoint to verify the failure and investigate how the browser focus affects the form's ShortcutKeys handling. Done means Ctrl+D activates the menu item while WebView2 is focused, as it does with the TextBox.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100