Controlling mouse with Python

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

    If you need to work with games. As explained in this post https://www.learncodebygaming.com/blog/pyautogui-not-working-use-directinput, some games like Minecraft or Fortnite have their own way of registering mouse / keyboard events. The way to control mouse and keyboard events is by using the brand new PyDirectInput library. Their github repository is https://github.com/learncodebygaming/pydirectinput, and has a lot of great information.
    Here's a quick code that does a mouse loop, and clicks:

    import pydirectinput  # pip install pydirectinput
    
    
    pydirectinput.moveTo(0, 500)
    pydirectinput.click()
    

提交回复
热议问题