PyAutoGUI一个纯Python的GUI自动化工具,其目的是可以用程序自动控制鼠标和键盘操作,多平台支持(Windows, Mac Os, Linux)

    GitHub: https://github.com/asweigart/pyautogui
    pip安装:
    >pip install pyautogui
    文档: https://pyautogui.readthedocs.io/en/latest

    1. import pyautogui
    2. from time import sleep
    3. # x, y = pyautogui.size()
    4. # print(x)
    5. # print(y)
    6. # pyautogui.moveTo(x/2, y/2)
    7. #
    8. # pyautogui.moveTo(347, 454)
    9. # pyautogui.click()
    10. # pyautogui.typewrite("hello world", interval=0.1)
    11. # pyautogui.press('esc')
    12. # pyautogui.keyDown('shift')
    13. # sleep(1)
    14. # pyautogui.press(['left', 'left','left','left','left'])
    15. # sleep(1)
    16. # pyautogui.keyUp('shift')
    17. # sleep(1)
    18. # pyautogui.hotkey('ctrl', 'c')
    19. # sleep(1)
    20. # pyautogui.press("right")
    21. # pyautogui.hotkey('ctrl', 'v')
    22. """
    23. hello world
    24. """
    25. # # 警告框
    26. # pyautogui.alert('这个消息弹窗是文字+OK按钮')
    27. # # 截图
    28. # pyautogui.screenshot('foo.png')
    29. # 例子,打开chrome浏览器,访问百度
    30. pyautogui.hotkey('win', 'q')
    31. sleep(1)
    32. pyautogui.typewrite("chrome", interval=0.25)
    33. sleep(1)
    34. pyautogui.press("enter")
    35. sleep(2)
    36. pyautogui.typewrite("www.baidu.com")
    37. sleep(1)
    38. pyautogui.press("enter")