Controlling mouse with Python

后端 未结 15 2471
滥情空心
滥情空心 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:18

    If you want to move the mouse, use this:

    import pyautogui
    pyautogui.moveTo(x,y)
    

    If you want to click, use this:

    import pyautogui
    pyautogui.click(x,y)
    

    If you don't have pyautogui installed, you must have python attached to CMD. Go to CMD and write: pip install pyautogui

    This will install pyautogui for Python 2.x.

    For Python 3.x, you will probably have to use pip3 install pyautogui or python3 -m pip install pyautogui.

提交回复
热议问题