[Python] Raspberry Pi OS mouse movement script

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make python script that will control mouse movements on my pi. But I can't get it move even a little bit. Code runs without any error logs, mouse just doesn't move.

    I am running my script in virtual env. I tried multiple libs, such as pynput, pyautogui, mouse. Here is what my code looks right now:

    import pyperclip
    import time
    from pynput.mouse import Button, Controller as MouseController
    from pynput.keyboard import Key, Controller as KeyboardController

    # WORKS
    text_to_copy = "Hello, World!"
    pyperclip.copy(text_to_copy)
    mouse = MouseController()
    keyboard = KeyboardController()
    keyboard.press(Key.ctrl)
    keyboard.press('v')
    keyboard.release('v')
    keyboard.release(Key.ctrl)

    # DOESNT WORK
    current_pos = mouse.position
    new_x = current_pos[0] + 500
    new_y = current_pos[1] + 50
    mouse.position = (new_x, new_y) # No error logs
    mouse.click(Button.left) # No error logs



    xdotool is installed, but xdotool mousemove 500 500 doesnt work.
    By 'doesn't work' I mean I don't see my mouse moving.
    Do you have any ideas whats going on?

    Continue reading...

Compartilhe esta Página