Context: We're using an on-screen keyboard on a touch screen kiosk to allow users to enter text. The backspace button is failing because the System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource becomes null.
Code Context:
if (System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource != null)
{
System.Windows.Input.KeyEventArgs ke =
new System.Windows.Input.KeyEventArgs(
System.Windows.Input.Keyboard.PrimaryDevice,
System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource,
0,
System.Windows.Input.Key.Back);
ke.RoutedEvent = UIElement.KeyDownEvent;
System.Windows.Input.InputManager.Current.ProcessInput(ke);
}
else
{
Console.Out.WriteLine("Problemo");
}
I can't use a KeyEventArgs with a null ActiveSource, and System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}") doesn't work either.