WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

Changing input language

Open olegsavelos opened this issue 2 years ago • 15 comments

I am trying to implement an input language change for an application using WebView2 hosted in WPF application, the problem is that most of the common ways to change the language don't work.

WPF InputLanguageManager.Current.CurrentInputLanguage no effect Win32 ActivateKeyboardLayout no effect

Changing the windows language manually does make WebView to use correct language, so the question is whether I am missing something or the only way is to programmatically switch windows input language ?

I have outlined the problem here

AB#43861304

olegsavelos avatar Mar 14 '23 07:03 olegsavelos

Hi @olegsavelos could you please provide some more information about this?

• Framework (WinUI, Win32, WinForms, UWP, WPF, etc)
• SDK and Runtime version.
• Operating System

novac42 avatar Mar 16 '23 08:03 novac42

WPF .NET 6.0.15 Windows 11 22h2 22621.1265

olegsavelos avatar Mar 16 '23 10:03 olegsavelos

@olegsavelos Thanks for providing the info. We've added it to our bug backlog.

novac42 avatar Mar 22 '23 07:03 novac42

@olegsavelos Thanks for providing the info. We've added it to our bug backlog.

Thanks! So you can confirm its a bug ?

olegsavelos avatar Mar 23 '23 13:03 olegsavelos

@olegsavelos , can you try CoreWebView2EnvironmentOptions.Language Property to see whether it helps with your scenario ?

lingamy avatar Mar 23 '23 17:03 lingamy

I have tried specifying the language in OnWebViewInitializing event handler

_BLAZOR_WEB_VIEW.BlazorWebViewInitializing = new EventHandler<BlazorWebViewInitializingEventArgs>(OnWebViewInitializing);

private void OnWebViewInitializing(object sender, BlazorWebViewInitializingEventArgs e)
 {
  e.EnvironmentOptions = new CoreWebView2EnvironmentOptions()
  {
      Language = "gr",
  };
 }

Nothing changes, all inputs are in English.

olegsavelos avatar Mar 28 '23 15:03 olegsavelos

@novac42 Is there any updates on this issue ?

olegsavelos avatar Jun 15 '23 09:06 olegsavelos

@olegsavelos sorry it's in our backlog but due to resource limitation we haven't got chance to work on it. May you help us understand the urgency of this issue? Is it a critical blocker?

novac42 avatar Jun 19 '23 03:06 novac42

@olegsavelos sorry it's in our backlog but due to resource limitation we haven't got chance to work on it. May you help us understand the urgency of this issue? Is it a critical blocker?

Kinda, we have a feature in the application change input language and it will just not work. You can confirm that this is a bug and dont require demo project right ?

olegsavelos avatar Jun 19 '23 13:06 olegsavelos

@novac42 is there any update on this issue or any workaround ? I cant be sure but it looks like the problem is related to input language change message I was able to set the language by sending broadcast window message like this

User32.SendNotifyMessage(new IntPtr(0xFFFF),(uint)WM.WM_INPUTLANGCHANGEREQUEST,(IntPtr)INPUTLANGUAGE.INPUTLANGCHANGE_SYSCHARSET,(IntPtr)culture.LCID);

This does change the language BUT the problem still remains where its not possible to detect current language change when its done by the windows shortcuts, the web view hosting window needs to loose focus in order to receive the change event and User32.GetKeyboardLayout will be reporting old value until its done.

olegsavelos avatar Aug 08 '23 08:08 olegsavelos

Adding to my previous comment I can add the following. If any other window has focus (foreground) changing language with shortcuts alt+shift does cause the User32.GetKeyboardLayout to report correct language for that window. If WPF edge web view has focus the HTML components (Inputs) do have correct input language but User32.GetKeyboardLayout will still report previous language until the window looses focus. @novac42

I have tried to see what potential workarounds could be done and so far the only viable one would be to use WH_SHELL hook but writing an native hook library is an overkill, please provide any potential workarounds.

olegsavelos avatar Aug 09 '23 15:08 olegsavelos

@novac42 should I expect this to be fixed or acknowledged at least?

olegsavelos avatar Aug 30 '23 10:08 olegsavelos

Should we expect any updates on this ?

olegsavelos avatar Sep 30 '23 10:09 olegsavelos

Hi! Sorry for the delay - there has been some personnel shifts. I will get someone to look into this for you

victorhuangwq avatar Oct 02 '23 19:10 victorhuangwq

This bug is still unfixed. WM_INPUTLANGCHANGE is not propagated to the host WPF window so there is no way to detect language change.

olegsavelos avatar Jun 24 '24 10:06 olegsavelos