1.代码
代码如下(示例):
import pyautogui
import pyperclip
import time
import cv2
def mouseclick(img):
location=pyautogui.locateCenterOnScreen(img,confidence=0.9)
if location is not None:
pyautogui.click(location.x*1680/3360,location.y*1050/2100,clicks=1,interval=0.2,duration=0.2,button="left")#
return True
else:
return False
def dotask(a):
if a["type"]=="点击":
img=a["content"]
return mouseclick(img)
elif a["type"]=="输入":
text=a["content"]
# print(text)
pyperclip.copy(text)# pyautogui.typewrite(text)
pyautogui.hotkey('command','v')
pyautogui.press('enter')
return True
#点击输入内容脚本
def ops(b,c):#c是内容
if b=='wx':
while True:
tasklist=[
{"type":"点击","content":"微信接收图标路径/*.png"},
{"type":"输入","content":c}
]
dotask({'type':'点击','content':'微信图标路径/*.png'})
i=0
while i<len(tasklist):
if(dotask(tasklist[i])):
i+=1
else:
print('监听中...')
elif b=='sf':
loc = "浏览器图标路径/*.png"
scaleClick(loc)
pyautogui.hotkey('command','t')
pyperclip.copy(c)
pyautogui.hotkey('command','v')
pyautogui.press('enter')
# print(pyautogui.size())
def scaleClick(loc):
getloc=pyautogui.locateCenterOnScreen(loc,confidence=0.9)
x,y = getloc
pyautogui.click(x*1680/3360,y*1050/2100,duration=0.2)#本机为mac,分辨率要*相应值
ops('sf','输入搜索内容')
总结
b为sf是浏览器,打开浏览器,显示内容c的结果
b为wx是微信,打开微信,打开接受一次信息的输入框,发送内容c