Hello,
Welcome to Microsoft Q&A.
I don’t know how your Keyboard layout implement in your UWP app. I simulate the keyboard input operation by using three buttons. In the following code, I use InputInjector
API to simulate keyboard input in the Click
events of buttons. The key point is to let the focus remain the input area within web page when pressing buttons which are used as keyboard. We do this by setting the value of FrameworkElement.AllowFocusOnInteraction property as false
in buttons.
Please check the following code as an example:
//MainPage.xaml
<StackPanel>
<StackPanel Orientation="Horizontal">
<Button Content="a" Click="Button_Click" Margin="10" AllowFocusOnInteraction="False"/>
<Button Content="b" Click="Button_Click" Margin="10" AllowFocusOnInteraction="False"/>
<Button Content="c" Click="Button_Click" Margin="10" AllowFocusOnInteraction="False"/>
</StackPanel>
<WebView Width="1000" Height="800" x:Name="WebViewControl"
Source="http://www.microsoft.com"/>
</StackPanel>
//MainPage.xaml.cs
private void Button_Click(object sender, RoutedEventArgs e)
{
InputInjector inputInjector = InputInjector.TryCreate();
var key = new InjectedInputKeyboardInfo();
var ch = (sender as Button).Content.ToString();
if (ch=="a")
{
key.VirtualKey = (ushort)(VirtualKey.A);
}
else if(ch=="b")
{
key.VirtualKey = (ushort)(VirtualKey.B);
}
else if(ch=="c")
{
key.VirtualKey = (ushort)(VirtualKey.C);
}
key.KeyOptions = InjectedInputKeyOptions.None;
inputInjector.InjectKeyboardInput(new[] { key });
key.KeyOptions = InjectedInputKeyOptions.KeyUp;
inputInjector.InjectKeyboardInput(new[] { key });
}
Let the search box in web page get the focus, click or touch the buttons to input character.
Please feel free to contact me if you have any concern.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.