Currently I used this snip code as a result from googling.
var eventArgs = new TextCompositionEventArgs(Keyboard.PrimaryDevice, new TextComposition(InputManager.Current, Keyboard.FocusedElement, "A")); eventArgs.RoutedEvent = TextInputEvent; var flag = InputManager.Current.ProcessInput(eventArgs);
It was working if I used Keyboard.Focus(TxtBox); and the TxtBox will be filled with the Keystroke.
But what I want really achieved is:
- 1.Drawing a box (for example, I draw box on one of the excel cell)
- 2.Click on the box coordinate (to change Keyboard Focus)
- 3.Send Keystroke to clicked excel cell
I have done step 1 and 2. But I can't find a way to do the third step.
Somehow, the click event (using mouse event) maybe not changing Keyboard Focus automatically.
So, how do I change Keyboard focus, if possible using coordinate ? Or maybe can I get IInputElement from a coordinate ? and then set keyboard focus to it. Of course, all of it outside from the main application window of the WPF.