using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
class Program
{
[DllImport("user32.dll")]
static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
static void Main(string[] args)
{
while (true)
{
if (GetCursorPos(out POINT point))
{
Color color = GetColorAt(point.X, point.Y);
if (color.R == 255 && color.G == 0 && color.B == 0)
{
ClickMouse(point.X, point.Y);
}
}
if (IsKeyPressed(Keys.Insert))
{
break;
}
Thread.Sleep(10); // Небольшая задержка для снижения нагрузки на CPU
}
}
static Color GetColorAt(int x, int y)
{
using (Bitmap screen = new Bitmap(1, 1))
using (Graphics g = Graphics.FromImage(screen))
{
g.CopyFromScreen(x, y, 0, 0, new Size(1, 1));
return screen.GetPixel(0, 0);
}
}
static void ClickMouse(int x, int y)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
}
static bool IsKeyPressed(Keys key)
{
return (GetAsyncKeyState((int)key) & 0x8000) != 0;
}
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(int vKey);
}
import pyautogui
import keyboard
def check_color():
while True:
x, y = pyautogui.position()
color = pyautogui.pixel(x, y)
if color == (255, 0, 0):
pyautogui.click () # Нажатие левой кнопки мыши
if keyboard.is _pressed('insert'):
break
check_color()