using BlumClicker; using System; using System.Drawing; using System.Drawing.Imaging;…
- User
using BlumClicker; using System; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Windows.Forms;
public static class Screenshot { [DllImport("user32.dll")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
code[DllImport("user32.dll")] private static extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect); [STAThread] public static void Start(string windowTitle) { IntPtr hWnd = FindWindow(null, windowTitle); if (hWnd == IntPtr.Zero) { Console.WriteLine("Window not found!"); return; } if (!GetWindowRect(hWnd, out Rectangle windowRect)) { Console.WriteLine("Could not get window rect."); return; } int screenWidth = windowRect.Width - windowRect.X; int screenHeight = windowRect.Height - windowRect.Y; using (Bitmap bitmap = new Bitmap(screenWidth, screenHeight, PixelFormat.Format32bppArgb)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(windowRect.X, windowRect.Y, 0, 0, bitmap.Size, CopyPixelOperation.SourceCopy); } Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat); IntPtr ptr = bmpData.Scan0; int bytes = Math.Abs(bmpData.Stride) * bitmap.Height; byte[] rgbValues = new byte[bytes]; ushort[,] cords = new ushort[bytes, 2]; Marshal.Copy(ptr, rgbValues, 0, bytes); bitmap.UnlockBits(bmpData); int cordsIdx = 0; for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { if (Program.paused) return; int index = y * bmpData.Stride + x * 4; byte blue = rgbValues[index]; byte green = rgbValues[index + 1]; byte red = rgbValues[index + 2]; int treshold1 = 15; int treshold2 = 5; bool first = Math.Abs(red - 183) < treshold1 && Math.Abs(green - 229) < treshold1 && Math.Abs(blue - 19) < treshold1; bool second = Math.Abs(red - 138) < treshold2 && Math.Abs(green - 226) < treshold2 && Math.Abs(blue - 238) < treshold2; if (first || second) { cords[cordsIdx, 0] = (ushort)x; cords[cordsIdx, 1] = (ushort)y; cordsIdx++; } } } if (cordsIdx > 0) { ushort[,] cordsTrim = new ushort[cordsIdx, 2]; for (int i = 0; i < cordsIdx; i++) { cordsTrim[i, 0] = cords[i, 0]; cordsTrim[i, 1] = cords[i, 1]; } Random random = new Random(); int idx = random.Next(0, cordsTrim.GetLength(0) - 1); Mouse.Click(windowRect.X + cordsTrim[idx, 0], windowRect.Y = cordsTrim[idx, 1]); } } } - Assistant
В коде, который вы привели, есть небольшая ошибка при вычислении координат для клика мышью. На строке, где вызывается
Mouse.Click, код неправильно присваивает значениеwindowRect.Y. Вместо этого необходимо просто использоватьwindowRect.Yдля Y-координаты клика. Также для генерации случайного индекса нужно убедиться, что не берутся некорректные значения.Вот исправленная часть вашего кода:
csharp