代码参考如下
整体思路是:
1、先利用 定位窗口的位置
2、然后将坐标利用icon_position = pyautogui.Point(x = 276, y = 1067)
3、用 pyautogui.moveTo(icon_position, duration = 0.3) 将鼠标移至该坐标
4、pyautogui.click(icon_position) 触发点击动作
5、pyperclip.copy("不理人的是小狗!")复制文本
6、pyautogui.hotkey("ctrl", "v") 粘贴文本
7、pyautogui.press("enter") 发送
界面操作 利用pyautogui库,键盘操作利用的是pyperclip库,定时启动利用random库
注释信息是定时发送内容
import pyautogui
import pyperclip
import time
import random
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler
from win10toast import ToastNotifier # 导入系统通知对象
import time # 系统时间模块
import datetime
from threading import Timer # 定时器
def main():
pyautogui.PAUSE = 0
current_time1 = int(time.time())
icon_position = pyautogui.Point(x = 276, y = 1067) # 任务栏图标位置
entry_position = pyautogui.Point(x = 1053, y = 772) # 输入框位置
pyautogui.moveTo(icon_position, duration = 0.3) # duration为执行时长,可选
pyautogui.click(icon_position)
pyautogui.moveTo(entry_position, duration = 0.3)
pyautogui.click(entry_position)
for i in range(1000):
pyperclip.copy("不理人的是小狗!")
pyautogui.hotkey("ctrl", "v")
pyautogui.press("enter")
time.sleep(0.73)
# current_time = int(time.time())
# time_1 = current_time - current_time1 + 100
# time.sleep(int(random.randint(5,10)))
# pyperclip.copy(f"小李不理我的第{time_1}秒,想哭")
# pyautogui.hotkey("ctrl", "v")
# pyautogui.press("enter")
# pyautogui.typewrite(
# [*list("liziying "), *list("nizaiganma "), *list("?"), "enter"],
# 0.1)
main()
# scheduler = BlockingScheduler() # 实例化
# scheduler.add_job(main, "date", run_date = datetime(2023, 1, 19, 11, 00, 50)) # 添加任务
# scheduler.start()
# def show_toast():
# print('当前时间:%s' % (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
# notify.show_toast(f"{notify_head}", f"{notify_text}", duration=5, threaded=True, icon_path='水杯.ico')
# while notify.notification_active():
# time.sleep(0.005)
# timer = Timer(notify_sen, show_toast)
# timer.start()
#
# show_toast()