kodun python hali
import ctypes
import time
from ctypes import wintypes
user32 = ctypes.windll.user32
gdi32 = ctypes.windll.gdi32
class POINT(ctypes.Structure):
_fields_ = [("x", wintypes.LONG), ("y", wintypes.LONG)]
class Color(ctypes.Structure):
_fields_ = [("r", ctypes.c_byte), ("g", ctypes.c_byte), ("b", ctypes.c_byte)]
class Form1:
def __init__(self):
self._is_tracking = False
self._target_color = Color(203, 192, 255) # Specify the target color here
self._last_position = POINT()
def get_cursor_pos(self):
cursor_pos = POINT()
user32.GetCursorPos(ctypes.byref(cursor_pos))
return cursor_pos
def get_dc(self, hwnd):
return user32.GetDC(hwnd)
def get_pixel(self, hdc, x, y):
return gdi32.GetPixel(hdc, x, y)
def form_mouse_down(self, e):
if e[2] == 2: # Right mouse button
self._is_tracking = True
self._last_position = self.get_cursor_pos()
def form_mouse_up(self, e):
if e[2] == 2: # Right mouse button
self._is_tracking = False
def timer_tick(self):
if self._is_tracking:
hdc = self.get_dc(0)
current_position = self.get_cursor_pos()
x = current_position.x - (75 // 2)
y = current_position.y - (75 // 2)
x = max(0, x)
y = max(0, y)
x = min(x, ctypes.windll.user32.GetSystemMetrics(0) - 75)
y = min(y, ctypes.windll.user32.GetSystemMetrics(1) - 75)
for i in range(x, x + 75):
for j in range(y, y + 75):
color = self.get_pixel(hdc, i, j)
pixel_color = Color(color & 0xFF, (color >> 8) & 0xFF, (color >> 16) & 0xFF)
if pixel_color.r == self._target_color.r and pixel_color.g == self._target_color.g and pixel_color.b == self._target_color.b:
user32.SetCursorPos(i + (75 // 2), j + (75 // 2))
self._last_position = POINT(i + (75 // 2), j + (75 // 2))
return
user32.SetCursorPos(self._last_position.x, self._last_position.y)
if __name__ == "__main__":
form = Form1()
user32.SetProcessDPIAware() # Enable DPI awareness
# Register mouse events
user32.SetWindowsHookExA(7, ctypes.WINFUNCTYPE(None, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int))(form.form_mouse_down), 0, user32.GetCurrentThreadId())
user32.SetWindowsHookExA(8, ctypes.WINFUNCTYPE(None, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int))(form.form_mouse_up), 0, user32.GetCurrentThreadId())
# Set up a timer for periodic execution
timer_interval = 100 # milliseconds
user32.SetTimer(None, 0, timer_interval, ctypes.WINFUNCTYPE(None)(form.timer_tick))
# Run the application
msg = wintypes.MSG()
while user32.GetMessageA(ctypes.byref(msg), 0, 0, 0) != 0:
user32.TranslateMessage(ctypes.byref(msg))
user32.DispatchMessageA(ctypes.byref(msg))
time.sleep(0.001) # Add a short delay to reduce CPU usage