Hey, I am trying to type a message into notepad without having to have it as my focus window (Foreground Window).
This is what I have so far:
const UInt32 WM_KEYDOWN = 0x0100;
const int VK_F5 = 0x74;
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
[STAThread]
private void button2_Click(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("Notepad");
foreach (Process proc in processes)
PostMessage(proc.MainWindowHandle, VK_TAB, VK_S, 0);
}
But this does not type S into notepad. When I use VK_F5, it displays the date/time and when I use VK_F1 that displays the help window but it does not type s.
I have thought about using SendKey but that requires me to be targeting Notepad.
Any help would be appreciated.
Thanks.