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

Add support for sending keyboard input to WebView2 - SendKeyEvent #3671

Open
53b4 opened this issue Jul 28, 2023 · 10 comments
Open

Add support for sending keyboard input to WebView2 - SendKeyEvent #3671

53b4 opened this issue Jul 28, 2023 · 10 comments
Assignees
Labels
feature request feature request tracked We are tracking this work internally.

Comments

@53b4
Copy link

53b4 commented Jul 28, 2023

Hi,
From some reasons inside CoreWebView2.AddHostObjectToScript(....) method I need to catch pressed keys and programmatically send its to webview2. Previously, in Cefsharp I used : ChromiumWebBrowser.GetHost().SendKeyEvent() .
Do we have some equivalent in webview2 ? I tried to use JS script, but here is problem because Monaco Editor for some subpages is used.

Please help
Regards,

AB#45786265

@53b4 53b4 added the question label Jul 28, 2023
@novac42 novac42 added the feature request feature request label Jul 31, 2023
@novac42
Copy link
Contributor

novac42 commented Jul 31, 2023

Hi @53b4, thanks for reaching out and right now we don't have an equivalent API for this, but we can take it as a feature request. Would you like to shed more light on why you need this - for example, what kind of app is this, and what use cases you are handling here to catch pressed keys?

@53b4
Copy link
Author

53b4 commented Jul 31, 2023

Hi, thank you for response.
We have Webview2 as embed control in some desktop application. When focus is on this window we have to capture some keys combinations that already used as a shortkeys in native application using custom IKeyboardHandler and send it to displayed page.

@novac42 novac42 added tracked We are tracking this work internally. and removed question labels Aug 1, 2023
@novac42
Copy link
Contributor

novac42 commented Aug 1, 2023

Thanks, I've added it to our feature backlog. Is this feature critical for your app? Any workaround available yet?

@53b4
Copy link
Author

53b4 commented Aug 2, 2023

Thanks; we are working to found out workaround; let you know results

@53b4
Copy link
Author

53b4 commented Aug 17, 2023

Sorry, I missed let you know. It is not critical.

@darbid
Copy link

darbid commented Aug 17, 2023

Sending keys to a page is something I'm missing too. Some input elements require "real events" to recognise the text value. In JavaScript the document.execommand method currently works but that was deprecated years ago. Other JavaScript events and event sequences to emulate key down and up are not reliable to work all the time.

@novac42
Copy link
Contributor

novac42 commented Aug 22, 2023

@darbid Thanks for the input. May you give some examples in your app's scenarios where input elements require real events to recognize the text value?

@darbid
Copy link

darbid commented Aug 22, 2023

This is not my app but an example of the input element.

https://research.wolterskluwer-online.de/document/55f290ba-966d-3e48-b8c6-69b6b63b890a

image

Do note if you inspect that example you can give the input element a value but it will not be recognised.

@ajtruckle
Copy link

@victorhuangwq
@champnic

I have the same issue and it seems a basic one really. We can tell WebView2 to listen for hotkeys to give us a chance to handle them, since we use them on our parent window, and when the browser has focus it would eat it up or handle it itself. So this direction is catered for with API.

But parent window to WebView2. Simple example:

  • Display a dialog which has a browser control.
  • Click onto the dialog background so it has focus.
  • Click CTRL + U and View Page Source does not work. It is eaten by the dialog.
  • Click the browser control to give it focus.
  • Now press CTRL + U and it works.

So we need a simple, uncomplicated way, when we use our Accelerator map and OnHotKey event, that we can just pass it, eg CTRL + U over to WebView2.

I really don't want to mess with JavaScript and other event handlers for what sounds like a simple SendKeyInput call. For me this adds a lot of confusion for users, even me, because wonder why it is not working sometimes.

It is why it was a godsend to have the API implemented for us to decide to let WebView2 handle hotkeys or do custom action.

I would really like to see this implemented.

@ajtruckle
Copy link

#4483

@champnic champnic changed the title equivalent of ChromiumWebBrowser.GetHost().SendKeyEvent() Add support for sending keyboard input to WebView2 - SendKeyEvent Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

6 participants