Lyn
Lyn

Reputation: 507

How to simulate keystroke in WPF, but outside the application?

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:

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.

Upvotes: 0

Views: 477

Answers (1)

Lyn
Lyn

Reputation: 507

Found it !

At: Installed InputSimulator via NuGet, no members accessible

It is working in most cases.

I said in most cases, because it is able to type in other window like excel application, but on other custom app window. There might be a case it won't work.

Hope it help for other people, looking for the same thing.

Upvotes: 2

Related Questions