I already got mouseclick to work with one issue. If I set delay between WM_MBUTTONDOWN and WM_MBUTTONUP to more than 5 ms it won't work. Why is that?
[DllImport("user32.dll")]
public static extern IntPtr
PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public void MouseClick(short x, short y)
{
IntPtr lParam = (IntPtr)((x & 0xFFFF) | ((y & 0xFFFF) << 16));
const uint WM_MBUTTONDOWN = 0x0201;
const uint WM_MBUTTONUP = 0x0202;
PostMessage(hwnd, WM_MBUTTONDOWN, IntPtr.Zero, lParam);
//System.Threading.Thread.Sleep(100);
PostMessage(hwnd, WM_MBUTTONUP, IntPtr.Zero, lParam);
}
Now, my goal is to send keystroke to minimized window (directx game). I tried using similar approach but nothing works. I bet that wParam is the problem.
const uint WM_KEYDOWN = 0x100;
const uint WM_KEYUP = 0x101;
const uint WM_CHAR = 0x102;
const int VK_W = 0x57;
const int VK_S = 0x53;
PostMessage(hwnd, WM_KEYDOWN, (IntPtr)VK_W, IntPtr.Zero);
PostMessage(hwnd, WM_KEYUP, (IntPtr)VK_W, IntPtr.Zero);
How do I get this to work?
Remember that the window will be minimized so I can't use SendKeys or SendInput.