Controlling mouse with Python

后端 未结 15 2375
滥情空心
滥情空心 2020-11-22 14:53

How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?

15条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 15:16

    Move Mouse Randomly On Screen

    It will move the mouse randomly on screen according to your screen resolution. check code below.

    Install pip install pyautogui using this command.

    import pyautogui
    import time
    import random as rnd
    
    #calculate height and width of screen
    w, h = list(pyautogui.size())[0], list(pyautogui.size())[1]
    
    while True:
        time.sleep(1)
        #move mouse at random location in screen, change it to your preference
        pyautogui.moveTo(rnd.randrange(0, w), 
                         rnd.randrange(0, h))#, duration = 0.1)
    

提交回复
热议问题