I\'ve found this answer which look like what I need:
How can I programmatically generate keypress events in C#?
Except for the fact I can\'t create an insta
To unit test a viewmodel I had to use a combination of OscarRyz and Elijah W. Gagne answer to make this work.
[TestMethod]
public void method_event_expected()
{
this.objectUnderTest.TestMethod(
new KeyEventArgs(Keyboard.PrimaryDevice, new HwndSource(0, 0, 0, 0, 0, "", IntPtr.Zero), 0, Key.Oem3)
{
RoutedEvent = Keyboard.KeyDownEvent
});
Assert.IsTrue(...)
}
Keyboard.PrimaryDevice.ActiveSource was null so I had to fake it with a dummy window and then I also needed the RoutedEvent to be assigned.