So when I cannot figure out why my PostMessage is not working. Here is what I have.
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);
private void Send_Click(object sender, EventArgs e)
{
uint WM_KEYDOWN = 0x0100;
Process p = Process.GetProcessesByName("notepad").FirstOrDefault();
IntPtr h = p.MainWindowHandle;
PostMessage(h,
WM_KEYDOWN,
(int)Keys.D, 0);
}
The above code doesn't work at all. Oddly enough though the below code does. Why doesn't postmessage work? I am on Windows 8 if thats any help.
[DllImport("user32.dll")]
static extern int SetForegroundWindow(IntPtr point);
private void SendUp_Click(object sender, EventArgs e)
{
Process p = Process.GetProcessesByName("notepad").FirstOrDefault();
if (p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
SendKeys.Send("D");
}
}