Guest User

Untitled

a guest
Jun 14th, 2024
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | Cybersecurity | 0 0
  1. import win32gui
  2. import win32con
  3. import win32api
  4. import time
  5. from ctypes import windll
  6.  
  7.  
  8. def find_window(title):
  9.     hwnd = None
  10.     found = False
  11.     while not found:
  12.         hwnd_list = []
  13.         win32gui.EnumWindows(lambda hwnd, param: hwnd_list.append(hwnd), None)
  14.         for hwnd in hwnd_list:
  15.             if win32gui.IsWindowVisible(hwnd):
  16.                 window_title = win32gui.GetWindowText(hwnd)
  17.                 if title.lower() in window_title.lower():
  18.                     return hwnd
  19.     return hwnd
  20.  
  21.  
  22. def click_center(hwnd):
  23.     left, top, right, bot = win32gui.GetWindowRect(hwnd)
  24.     width = right - left
  25.     height = bot - top
  26.     center_x = int(left + width / 2)
  27.     center_y = int(top + height / 2)
  28.     # Получаем координаты в формате LONG
  29.     lParam = win32api.MAKELONG(center_x, center_y)
  30.     # Симулируем клик мышью
  31.     win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
  32.     win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, lParam)
  33.  
  34.  
  35. if __name__ == "__main__":
  36.     target_window_title = 'Banana'
  37.     while True:
  38.         hwnd = find_window(target_window_title)
  39.  
  40.         if hwnd:
  41.             print(f"Найдено окно {target_window_title}")
  42.             click_center(hwnd)
  43.             print("Клик по центру окна выполнен")
  44.         else:
  45.             print(f"Окно {target_window_title} не найдено")
  46.  
  47.         time.sleep(1)
  48.  
Advertisement
Add Comment
Please, Sign In to add comment