Controlling mouse with Python

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

    As of 2020, you can use mouse:

    import mouse
    mouse.move("500", "500")
    mouse.left_click()
    

    Features

    • Global event hook on all mice devices (captures events regardless of focus).
    • Listen and sends mouse events.
    • Works with Windows and Linux (requires sudo).
    • Pure Python, no C modules to be compiled.
    • Zero dependencies. Trivial to install and deploy, just copy the files.
    • Python 2 and 3
    • Includes high level API (e.g. record and play).
    • Events automatically captured in separate thread, doesn't block main program.
    • Tested and documented.

提交回复
热议问题