Python code to automate desktop activities in windows

前端 未结 5 1895
旧巷少年郎
旧巷少年郎 2020-12-02 11:16

I want to automate desktop activities in Windows environment using Python. How it can be done? Some examples will also be helpful.

By desktop activities, I mean acti

5条回答
  •  佛祖请我去吃肉
    2020-12-02 12:07

    You can use PyAutoGUI which provide a cross-platform Python way to perform GUI automation.

    Mouse Control

    Here is a simple code to move the mouse to the middle of the screen:

    import pyautogui
    screenWidth, screenHeight = pyautogui.size()
    pyautogui.moveTo(screenWidth / 2, screenHeight / 2)
    

    Related question: Controlling mouse with Python.

    Keyboard Control

    Example:

    pyautogui.typewrite('Hello world!')                 # prints out "Hello world!" instantly
    pyautogui.typewrite('Hello world!', interval=0.25)  # prints out "Hello world!" with a quarter second delay after each character
    

    Message Box Functions

    It provides JavaScript-style message boxes.

    And other.


    For other suggestions, check: Python GUI automation library for simulating user interaction in apps.

提交回复
热议问题