正文
python脚本检测出现指定标题窗口并点击鼠标
import time import pyautogui import win32gui def find_window(title): hwnd = win32gui.FindWindow(None, title) return hwnd def click_relative_position(hwnd, x, y): rect = win32gui.GetWindowRect(hwnd) win32gui.SetForegroundWindow(hwnd) #点击窗口内坐标 #pyautogui.click(rect[0] + x, rect[1] + y) #点击窗口内比例的位置坐标 pyautogui.click(rect[0] + int((rect[2]-rect[0])*0.7), rect[1] + int((rect[3]-rect[1])*0.9)) # 循环检测 while True: # 查找窗口 hwnd = find_window("Window Title") # 如果找到匹配窗口 if hwnd != 0: # 点击相对坐标 time.sleep(0.1) try: click_relative_position(hwnd, 300, 700) except Exception as e: print(e) print("$$$$$发现目标!点击..."+ time.strftime("%H:%M:%S", time.localtime())) time.sleep(0.2) else: print("没找到,继续等待..."+ time.strftime("%H:%M:%S", time.localtime())) time.sleep(0.2)
- 上一篇: vbs脚本检测出现指定标题窗口并点击鼠标
- 下一篇: linux设置python脚本开机启动
猜你喜欢
- 2024-01-08vbs脚本检测出现指定标题窗口并点击鼠标
- 2024-01-08python推送钉钉群消息
- 2024-01-04linux后台执行python脚本
- 2024-01-03Ubuntu安装Python3.9
- 搜索