[Python] How do I fix this code? the cursor just fly everywhere even thought I want to...

Discussão em 'Python' iniciado por Stack, Junho 4, 2025.

  1. Stack

    Stack Membro Participativo

    Was trying to make a code to drag something onto another thing with different color pixel, one of them keep changing color with tolerance over 70 which i just took the r value since it only range from 1 to 3. The other thing that is being dropped at has value of 119, 23, 111 rgb with tolerance of 5, they also have a 50% chance of switching place when being dragged to.

    from pyautogui import *
    import pyautogui
    import time
    import keyboard
    import random
    import win32api, win32con

    time.sleep (2)
    #region=(926,599,320,230)

    def drag_and_drop (a, b):
    win32api.SetCursorPos(a)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    win32api.SetCursorPos(n)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

    while keyboard.is_pressed('q') == False:
    pic = pyautogui.screenshot(region=(926,599,320,230))

    width, height = pic.size

    for x in range(0,width,40):
    for y in range(0,height,25):

    r,g,b = pic.getpixel((x,y))

    pyautogui.onScreen(926,599)
    pyautogui.moveTo(r in range (1,3))
    pyautogui.mouseDown()
    pyautogui.moveTo (g == 23)
    pyautogui.mouseUp()
    time.sleep(0.05)
    break


    Also was confused on how to integrate 2 different coordinate into a single def.

    Continue reading...

Compartilhe esta Página