I have an application that automatically simulates some keystrokes. I am using following code for this:
public void goNextPage()
{
WindowsInput.InputSimulator ip = new WindowsInput.InputSimulator();
ip.Keyboard.ModifiedKeyStroke(new[] { WindowsInput.Native.VirtualKeyCode.CONTROL, WindowsInput.Native.VirtualKeyCode.MENU }, WindowsInput.Native.VirtualKeyCode.VK_Y);
Thread.Sleep(5000);
}
Input Simulator is an alternative to SendKeys()
. I shifted to this because I was having the same problem with SendKeys()
.
The problem is that sometimes the form on which keys are simulated needs to be minimized by the user. I tried minimizing the form but instead of sending keys to the its owner form, it sends them to the newly activated form or the active application like Visual Studio and Google Chrome. For example: When I started to type something in Chrome's address bar and at the same time my application sends SHIFT
key, my typed data shifted to capital letters or symbols on number keys.
So is it possible to send keys to a deactivated form? Or is it against the operating system rules? Can it be overridden?