python 模拟鼠标键盘操作 pyautogui库
2022-08-09 14:26 起个昵称 阅读(463) 评论(0) 编辑 收藏 举报Python自动化控制鼠标和键盘操作—— PyAutoGUI
https://blog.csdn.net/weixin_43964993/article/details/119845407#t18
找到坐标 position
点击 click(坐标)
写入write('hihi')
按回车press('enter')
。。。
一个示例
1 import pyautogui as p 2 from random import randint 3 from time import sleep 4 5 cnt = 0 6 7 while True: 8 which_wind = randint(1,2) 9 10 cnt += 1 11 print(f'总输入指令次数:{cnt}') 12 13 # 点击server窗口 14 if which_wind == 1: 15 p.click(434, 417) 16 sleep(3) 17 # 输入字符 18 a = randint(1, 2) 19 if a == 1: 20 p.write('w') 21 elif a == 2: 22 p.write('r') 23 # 按回车键 24 p.press('enter') 25 sleep(3) 26 # 点击client窗口 27 elif which_wind == 2: 28 p.click(1077, 417) 29 sleep(3) 30 # 输入字符 31 b = randint(1, 2) 32 if b == 1: 33 p.write('w') 34 elif b == 2: 35 p.write('r') 36 # 按回车键 37 p.press('enter') 38 sleep(3)