Open michalh2020 opened 3 years ago
Hey @michalh2020 - thanks for the feedback. Are you looking for all keypresses to be handled by the Preview/KeyDown events? If so I believe that request is tracked in #112.
@champnic Thank you for your response. I need to capture some keys using PreviewKeyPress in WebView2 (eg Shift + D) and pass them to the MainWindow (these are shortcut keys and work when focus is not in WebView2).
For example, in Delphi 10.3, PreKeyEvent was running with dCEF4-Chromium and there I was able to capture keys and cancel Chromium.
I dream of the same in Visual Studio 2019 + WebView2 :)
Or another similar use in WebView2, I have two WebView2s and I want to pass a Uri to another WebView2 from the html menu:
_private void webView2LeftNavigationStarting (object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e) { if (LeftLinkToCentrer == true) { webView2Center.Source = new Uri (e.Uri); e.Cancel = true; } }
I thought PreviewKewDown would do the same as NavigationStarting - it will be able to interrupt and forward the button action like NavigationStarting cancel opening Uri.
I believe you should be able to achieve something similar with the KeyDown event. If you mark the event as handled (e.Handled = true;) that should stop the WebView2 from handling that shortcut itself. Can you give that a try? Thanks!
@champnic Unfortunately, KeyDown from WebView2 does not transfer all keys, for example from another System.Windows.Forms.TextBox control, Shift + D works, Microsoft.Web.WebView2.WinForms.WebView2 Shift + D does not. Only some keys in WebView2, eg Shift + Ctrl, but not everything like TextBox.
_private void webView2Center_KeyPress(object sender, KeyPressEventArgs e)
{
Debug.Write("\n webView2Center_KeyPress " + e.KeyChar.ToString() + " " + sender.ToString());
}
private void webView2Center_KeyUp(object sender, KeyEventArgs e)
{
Debug.Write("\n webView2Center_KeyUp "+e.Alt + " " + e.Control + " " + e.KeyData + " "+ sender.ToString());
}
private void textBoxwww_KeyPress(object sender, KeyPressEventArgs e)
{
Debug.Write("\n textBoxwww_KeyPress " + e.KeyChar + " "+ sender.ToString());
}
private void textBoxwww_KeyUp(object sender, KeyEventArgs e)
{
Debug.Write("\n textBoxwww_KeyUp " + e.Alt + " " + e.Control + " " + e.KeyData +" " + sender.ToString());
}_
Thanks for the added info - I've added this bug to our backlog.
Description
WebView2_PreviewKeyDown not work. WebView2_KeyDown only keys: ControlKey/Apps/Menu/Capital/Escape/F1-F12/Home/End/Next/PageUp/Delete/Insert/Right/Left/Up/Down
Version SDK: 1.0.774.44 or 1.0.824-prerelease Runtime: 89.0.774.77 or 90.0.818.41 Framework: 4.6.1 or 4.8 OS: Win10 Pro [Version 10.0.18363.1440]
Repro Steps
Screenshots
Additional context
AB#32770120