-1

Hi I want to type text in textbox by sendind keys from keyboard.

Xaml:

<Button Name="Start" Margin="20" Grid.Column="0" Grid.Row="0" VerticalAlignment="Top" Click="Start_Click">Start</Button>
<TextBox Name="test" Grid.Column="0" Grid.Row="2"></TextBox>

C#:

private async void Start_Click(object sender, RoutedEventArgs e)
{
 Keyboard.Focus(test);
 await wait(1);
 SendKeys.Send("s"); 
}

But this gives me an error. What I made wrong ?

Finchsize
  • 935
  • 2
  • 17
  • 34

1 Answers1

3

I think the problem is you are using "SendKeys" which is Windows Forms technology to interact with WPF components, which is not Windows Forms technology. You need to send events to the TextBox like this:

TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, test, "s"));
Mishax
  • 4,442
  • 5
  • 39
  • 63