WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: OnKeyDown event not received when typing keys "p", "o", "i" on PDFViewer

Open thanhbao1996 opened this issue 1 year ago • 4 comments

What happened?

When I open a pdf file on webview 2, I want to block users from using Ctrl + P to print. The OnKeyDown event doesn't recognize the P key so I can't intercept it

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime), Prerelease (Edge Canary/Dev/Beta)

Runtime Version

126.0.25.92.102

SDK Version

No response

Framework

Winforms

Operating System

Windows 10

OS Version

Enterprise LTSC 1809

Repro steps

  1. Attach the OnKeyDown event to webview2
  2. Open a PDF file
  3. Press P, O, I....

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

AB#53007917

thanhbao1996 avatar Aug 01 '24 02:08 thanhbao1996

@thanhbao1996 are you referring to javascript onkeydown event or winforms keydown event? For javascript I am seeing p, o, and i onkeydown events even when preceded by 'ctrl.'

For .NET WebView2 controls, accelerator key combinations should trigger KeyDown event, so you should listen to that and suppress from there. I'm seeing that I can suppress Ctrl+O combination by doing this. However, I'm seeing Ctrl+P is not working for some reason.

For that I will file a bug on our side and track this issue,

johna-ms avatar Aug 02 '24 23:08 johna-ms

✅ Successfully linked to Azure Boards work item(s):

champnic avatar Aug 02 '24 23:08 champnic

@johna-ms Just as you mentioned, I am using the .NET WebView2 controls version and I am using the KeyDown event of the control. I also tried again, and when I press the 'o' key and set a breakpoint at the KeyDown event, it still does not respond. Make sure you are doing it on the content of the PDF file.

thanhbao1996 avatar Aug 03 '24 00:08 thanhbao1996

@thanhbao1996 for .NET WebView2 it is expected that most keyboard events will not trigger the control's KeyDown/KeyUp handlers. Those will only respond to certain accelerator key presses. The way to get normal key events to work with the .NET control is to add a javascript onkeydown listener and use WebMessage to communicate that to the control

johna-ms avatar Aug 05 '24 22:08 johna-ms