Controlling mouse with Python

后端 未结 15 2378
滥情空心
滥情空心 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 15:32

    Try with the PyAutoGUI module. It's multiplatform.

    pip install pyautogui
    

    And so:

    import pyautogui
    pyautogui.click(100, 100)
    

    It also has other features:

    import pyautogui
    pyautogui.moveTo(100, 150)
    pyautogui.moveRel(0, 10)  # move mouse 10 pixels down
    pyautogui.dragTo(100, 150)
    pyautogui.dragRel(0, 10)  # drag mouse 10 pixels down
    

    This is much easier than going through all the win32con stuff.

提交回复
热议问题