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

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

Open
thanhbao1996 opened this issue Aug 1, 2024 · 4 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@thanhbao1996
Copy link

thanhbao1996 commented Aug 1, 2024

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 thanhbao1996 added the bug Something isn't working label Aug 1, 2024
@johna-ms
Copy link
Contributor

johna-ms commented Aug 2, 2024

@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 johna-ms added the tracked We are tracking this work internally. label Aug 2, 2024
@champnic
Copy link
Member

champnic commented Aug 2, 2024

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

@thanhbao1996
Copy link
Author

@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.

@johna-ms
Copy link
Contributor

johna-ms commented Aug 5, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

3 participants