Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 498
user11913531 Avatar asked Jan 30 '26 22:01

user11913531


1 Answers

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()" });
like image 116
user11913531 Avatar answered Feb 01 '26 11:02

user11913531



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!