执行 pip install pyautogui
提示:
Could not find a version that satisfies the requirement Pillow>=6.2.1 (from pyscreeze>=0.1.21->pyautogui) (from versions: none)
参考:https://www.jianshu.com/p/3de67550cea6 ,首先从
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow 下载了 Pillow?7.1.1?cp38?cp38?win_amd64.whl (我安装的python3.8 win10是64位)
执行:
pip install e:\downloads\Pillow-7.1.1-cp38-cp38-win_amd64.whl
然后:
pip install pyautogui
成功。
为了输入中文,参考https://www.cnblogs.com/zwc--blog/p/11079986.html
还需要pyperclip
然后,参考https://www.cnblogs.com/ffrs/p/11358308.html和https://blog.csdn.net/wenq_yang/article/details/82910427 做个测试
另外,还有pywinauto 参考:https://www.cnblogs.com/baihuitestsoftware/articles/9317368.html
顺便写个小例子:打开计算器,然后运行脚本找计算器窗口,输入1+2=
import pyautogui,time pyautogui.hotkey(‘win‘, ‘r‘) time.sleep(1) pyautogui.press(‘shift‘)#因为默认中文输入,所以切换输入法为英文状态 pyautogui.typewrite(‘calc.exe‘) pyautogui.press(‘enter‘) time.sleep(3) pyautogui.press(‘1‘) pyautogui.press(‘+‘) pyautogui.press(‘2‘) pyautogui.press(‘=‘)
补充,考虑输入法的状态控制。后来添加了英文键盘,并设置热键以切换英文输入状态,参考https://jingyan.baidu.com/album/63acb44a7cfea461fdc17e5f.html?picindex=3
原文:https://www.cnblogs.com/pu369/p/12654835.html