How can I simulate a foreign window as the focused window? I need this, because I want to send keys to the notepad window and it only works if the notepad window has the focus. But I don't want to loose the focus on my own window.
public IntPtr Find(string taskName, string windowName)
{
return Fenster.FindWindow(taskName, windowName);
}
public void Send(IntPtr hwnd, string text)
{
if (!hwnd.Equals(IntPtr.Zero))
{
SendKeys.Send(text);
}
}
public bool SetForeground(IntPtr hwnd)
{
return SetForegroundWindow(hwnd);
}
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lp1, string lp2);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
Thanks a lot!