Trying to write a bot for online games, at this stage of my task is to determine the color of the monster , hover over it and pressing a double click . All this I learned to do on the desktop by means of creating a loop that iterates through the pixels after which the mouse moves over this pixel reads color and if satisfies twice clicks in place. But as soon as the mouse comes to the game window it simply pereprygivaet.Ya understand is why this is happening because the game is controlled by its own code , but I can still control the mouse in the game? I was just in the first write something like ...
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
[DllImport("gdi32.dll")]
static extern IntPtr CreateDC(string strDriver,
string strDevice, string strOutput, IntPtr pData);
[DllImport("user32.dll")]
static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
[DllImport("gdi32.dll")]
static extern bool DeleteDC(IntPtr hdc);
static public System.Drawing.Color GetPixelColor(int x, int y)
{
IntPtr hdc = CreateDC("Display", null, null, IntPtr.Zero);
uint pixel = GetPixel(hdc, x, y);
ReleaseDC(IntPtr.Zero, hdc);
Color color = Color.FromArgb((int)(pixel & 0x000000FF),
(int)(pixel & 0x0000FF00) >> 8,
(int)(pixel & 0x00FF0000) >> 16);
DeleteDC(hdc);
return color;
}
public Form1()
{
InitializeComponent();
Visible = false;
}
private void Form1_Load(object sender, EventArgs e)
{
}
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap pix = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
this.Hide();
Win32.POINT p = new Win32.POINT();
int check = 0;
while (check!=3)
{
for (int i = 0; i < 768; i += 3)
{
for (int j = 0; j < 1366; j+=7)
{
Color color = GetPixelColor(p.x, p.y);
p.x = Convert.ToInt16(j);
p.y = Convert.ToInt16(i);
Win32.SetCursorPos(p.x, p.y);
if (Color.FromArgb(222, 11, 11) == color)
{
MessageBox.Show("1");
Thread.Sleep(3000);
Win32.ClientToScreen(Handle, ref p);
mouse_event((int)(MouseEventFlags.LEFTDOWN), p.x, p.y, 0, 0);
mouse_event((int)(MouseEventFlags.LEFTUP), p.x, p.y, 0, 0);
}
}
}
check++;
}