Search code examples
c#.netwebviewuwpon-screen-keyboard

UWP unable to enter data in textbox in webview with custom OSK


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"/>


Solution

  • 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()" });