pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pynput
from pynput.keyboard import Key, Controller # pynput库允许你控制和监测/听你的输入设备(keyboard)
# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pynput
import time # 内部封装了一些获取时间戳和字符串形式时间的函数
keyboard = Controller()
content = input("请输入你想要循环的内容:")
freq = eval(input("请输入你想要循环的次数:"))
print("请将光标移动到会话框")
time.sleep(2)
for i in range(3): # 模拟倒计时,没有需要可以去掉
print(f'距离程序运行还有{3 - i}秒')
time.sleep(1)
for i in range(freq):
keyboard.type(content)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
# When called, functions as if a key were pressed and held on your keyboard. Useful when using modifier keys. To end the key press, use Keyboard.release()
# 模拟回车键的使用
time.sleep(0.1) # 发送时间间隔 可自己设置
print("消息发送完毕,请关闭窗口")