Reputation: 81
First of all I already have a working solution I just need some explanation on what is happening here.
I have the following code:
var e = new KeyEventArgs(Keyboard.PrimaryDevice,
Keyboard.PrimaryDevice.ActiveSource,
Environment.TickCount,
Key.D1)
{
RoutedEvent = Keyboard.KeyDownEvent
};
InputManager.Current.ProcessInput(e);
The purpose of this code is to add the value 1 to a currently focused textbox (= Keyboard.PrimaryDevice.ActiveSource). But if I execute this code the text which is contained in the textbox wont change. But the routed "KeyDown" event is executed.
If I change the code from above to this, it is working:
var eventArgs = new TextCompositionEventArgs(Keyboard.PrimaryDevice,
new TextComposition(InputManager.Current,
Keyboard.FocusedElement, "1"))
{
RoutedEvent = ContentElement.TextInputEvent
};
InputManager.Current.ProcessInput(eventArgs);
Now my question is, why is it not working with the first example. In my understanding if the control receives a KeyDown Event the result should be that the text is changed? The interessting part is if I want to send special key events like Enter or Backspace I HAD to use code example 1 code example 2 wont work there.
This is a little bit tricky and I thought maybe someone can enlighten me?
Thank you in advance
Upvotes: 2
Views: 334