I am in the process of expanding a small bot I made for "clicker" browser games (clicker heroes, candy clicker, etc.)
Originally, I was sending clicks like this:
var screenPoint = Cursor.Position;
var handle = WindowFromPoint(screenPoint);
if (handle != IntPtr.Zero)
{
SendMessage(handle, Win32.WM_RBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(handle, Win32.WM_RBUTTONUP, IntPtr.Zero, IntPtr.Zero);
}
But this obviously causes the problem of the window needing to be in front.
I want to be able to send clicks to the window handle itself, so I get the handle like so:
winHandle = Win32.FindWindow("PlayerClient", "Clicker Heroes");
SendMessage(winHandle , Win32.WM_RBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
...
The problem now is, how do I specify the Point or xy-coordinates that I wish it to send the click to? The documentation mentions something about the LParam
taking a Point, but doesn't provide any examples.
Thanks for your help.
From:
You need to pass the coordinates to
SendMessage
via thelParam
parameter.If you want a helper function to build the LPARAM I suggest starting with the following for a 32 bit program: