2

first of all sorry for my bad English.

I have developed a bot program for a game. Everything works fine, but I want to improve it.

I am using 'PostMessage' to send keyboard and mouse input to a specific window handle. The mouse input is tricky, because the game don't accept the input if the cursor is not at the given position. Because of that i have to use 'SetCursorPos' before the usage of 'PostMessage'.

I want to improve my code, to be able to use my PC while the program is running. That means i don't want the cursor to jump across my desktop. Is there a solution with 'PostMessage' without the need of setting the cursor Position or something similar?

Here is a example of my code:

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", EntryPoint = "PostMessageA", SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);

private const uint WM_LBUTTONDOWN = 0x0201;

public static void MouseLeftDown(IntPtr hWnd, int x, int y)
{
SetCursorPos(x, y);
PostMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, new IntPtr(MAKEPARAM(x, y)));
}

private static int MAKEPARAM(int lWord, int hWord)
{
return ((lWord & 0xFFFF) | (hWord << 0x10));
}
Tou
  • 21
  • 1
  • Possible duplicate of [programmatically mouse click in another window](http://stackoverflow.com/questions/10355286/programmatically-mouse-click-in-another-window) – lokusking Aug 25 '16 at 16:01

0 Answers0