[Python] Python mouse movement

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    So I like to use python to simulate mouse movement and clicking and I can never get the mouse to move to the correct coordinates. I have a different script that tells me coordinates corresponding to mouse position and I know it does work, it's just the mouse movement that I have issues with. Here is an example script:

    import json
    import random
    import time
    from pynput.mouse import Controller, Button

    mouse = Controller()

    with open("anydesk_coords.json", "r") as f:
    coords = json.load(f)

    x1, y1 = coords["top_left"]
    x2, y2 = coords["bottom_right"]

    left = min(x1, x2)
    top = min(y1, y2)
    right = max(x1, x2)
    bottom = max(y1, y2)

    click_x = random.randint(left, right)
    click_y = random.randint(top, bottom)

    mouse.position = (click_x, click_y)
    time.sleep(0.3)
    mouse.click(Button.left, 1)


    I end up adjusting coordinates manually and I am sure there is something I'm doing wrong. I went to the pynput page but I'm still pretty new to coding, which is why im doing this in python.

    Continue reading...

Compartilhe esta Página