3
votes

I have an angular app running in webview and a custom OnScreen Keyboard(OSK) in uwp. I am unable to enter data in the textbox present in webview using the custom OSK though it is working fine for normal UWP textbox. It seems to lose focus when i click on OSK.

I have tried WebView.Focus(FocusState.Programmatic) and invoking scripts using InvokeScriptAsync for setting the focus back to the webview in WebView LostFocus event but nothing worked.

I tried using focusmanager as well.

FocusMovementResult result;
result = await FocusManager.TryFocusAsync(WebView, FocusState.Programmatic);

I am injecting input in the textbox using InputInjector.

inputKey.VirtualKey = ((ushort)((VirtualKey)Enum.Parse(typeof(VirtualKey), input.Text, true)));
inputInjector.InjectKeyboardInput(new[] { inputKey });

Also the AllowFocusOnInteraction property is set to False for OSK. <app:Keyboard x:Name="keyboard" AllowFocusOnInteraction="False"/>

1
Hi, in WebView, a touch keyboard is recommended. Or you can try to modify the OSK, first complete the text input in the OSK, and then import the completed text into the WebView.Richard Zhang - MSFT
Hi @Richasy thank you but implementing OSK in the webview will result in tight coupling. And first completing the input and then importing it into the webview textbox will result in a bad user expeience. This way user will be able to see the complete text after typing. Also i am having issue in inserting the text in the selected textbox in webview,user11913531
Hi @user11913631, Maybe my statement is not clear. I recommend using Windows 10 Software Keyboard. And I try to use the default OSK (osk.exe), which can keep the focus of the input box in WebView. If necessary, can you check if your OSK is abnormal?Richard Zhang - MSFT
@Richasy I wanted a customized keyboard. Thanks for the help :)user11913531

1 Answers

1
votes

I was able to resolve it by notifying UWP with window.external.notify about the blur event using event listener and with this notified command set focus back to webview using

webview.Focus(FocusState.Programmatic);
await webView.InvokeScriptAsync(@"eval", new string[] { "document.focus()" });