感兴趣的可以看看
from random import random, randint
import pyautogui
import time
from [p]网页链接 import Listener
import threading
flag = True
# 定义鼠标点击事件的回调函数
def on_click(x, y, button, pressed):
# 如果右键被按下,停止监听并退出
if [p]网页链接 == 'right' and pressed:
global flag
print("右键点击")
# 返回 False 停止监听
flag = False
return False
# 启动鼠标监听的线程
def start_listener():
with Listener(on_click=on_click) as listener:
listener.join()
if __name__ == '__main__':
# 创建并启动监听线程
listener_thread = threading.Thread(target=start_listener)
listener_thread.start()
time.sleep(5)
while flag:
# 等待几秒钟,让你切换到目标窗口
time.sleep(0.5)
# 移动鼠标到屏幕的 (x, y) 坐标
pyautogui.moveTo(1280, 720)
# 单击鼠标
pyautogui.click()
code = randint(1111111,2030000)
print(code)
# 使用 Ctrl + A 选择所有文本
pyautogui.hotkey('ctrl', 'a')
# 使用 Delete 键删除选中的文本
pyautogui.press('delete')
# 输入文本
pyautogui.write(str(code), interval=0.08)
# 移动鼠标到屏幕的 (x, y) 坐标
pyautogui.moveTo(1380, 720)
# 单击鼠标
pyautogui.click()
# 移动鼠标到屏幕的 (x, y) 坐标
pyautogui.moveTo(1280, 760)
# 单击鼠标
pyautogui.click()