Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import win32gui
- import win32con
- import win32api
- import time
- from ctypes import windll
- def find_window(title):
- hwnd = None
- found = False
- while not found:
- hwnd_list = []
- win32gui.EnumWindows(lambda hwnd, param: hwnd_list.append(hwnd), None)
- for hwnd in hwnd_list:
- if win32gui.IsWindowVisible(hwnd):
- window_title = win32gui.GetWindowText(hwnd)
- if title.lower() in window_title.lower():
- return hwnd
- return hwnd
- def click_center(hwnd):
- left, top, right, bot = win32gui.GetWindowRect(hwnd)
- width = right - left
- height = bot - top
- center_x = int(left + width / 2)
- center_y = int(top + height / 2)
- # Получаем координаты в формате LONG
- lParam = win32api.MAKELONG(center_x, center_y)
- # Симулируем клик мышью
- win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
- win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, lParam)
- if __name__ == "__main__":
- target_window_title = 'Banana'
- while True:
- hwnd = find_window(target_window_title)
- if hwnd:
- print(f"Найдено окно {target_window_title}")
- click_center(hwnd)
- print("Клик по центру окна выполнен")
- else:
- print(f"Окно {target_window_title} не найдено")
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment