|
@@ -0,0 +1,80 @@
|
|
|
+import math
|
|
|
+import time
|
|
|
+
|
|
|
+import win32api
|
|
|
+import win32con
|
|
|
+import win32gui
|
|
|
+from pynput.mouse import Controller
|
|
|
+
|
|
|
+target = Controller()
|
|
|
+
|
|
|
+
|
|
|
+def get_all_windows():
|
|
|
+ windows = []
|
|
|
+ win32gui.EnumWindows(lambda hwnd, windows: windows.append(hwnd), windows)
|
|
|
+ return windows
|
|
|
+
|
|
|
+
|
|
|
+def get_window_title(hwnd):
|
|
|
+ return win32gui.GetWindowText(hwnd)
|
|
|
+
|
|
|
+
|
|
|
+def find_chrome():
|
|
|
+ windows = get_all_windows()
|
|
|
+ target = []
|
|
|
+ for hwnd in windows:
|
|
|
+ title = get_window_title(hwnd)
|
|
|
+ if "Google Chrome" in title:
|
|
|
+ target.append(hwnd)
|
|
|
+ return target
|
|
|
+
|
|
|
+
|
|
|
+def get_screen_resolution():
|
|
|
+ return win32api.GetSystemMetrics(win32con.SM_CXSCREEN), win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
|
|
|
+
|
|
|
+
|
|
|
+def arrange_windows():
|
|
|
+ window_handles = find_chrome()
|
|
|
+ num_windows = len(window_handles)
|
|
|
+ middle_point = []
|
|
|
+ screen_width, screen_height = get_screen_resolution()
|
|
|
+ if num_windows == 0:
|
|
|
+ return
|
|
|
+
|
|
|
+ base_width = screen_width // (num_windows // 2)
|
|
|
+ base_height = screen_height // 2 - 5
|
|
|
+ for i, hwnd in enumerate(window_handles):
|
|
|
+ y = 0
|
|
|
+ x = i * base_width
|
|
|
+ if i > 2:
|
|
|
+ y = base_height - 1
|
|
|
+ x = (i - 3) * base_width
|
|
|
+ middle_point.append((x + math.ceil(base_width / 2), y + math.ceil(base_height / 2)))
|
|
|
+ win32gui.SetWindowPos(hwnd, win32con.HWND_TOP, x, y, base_width, base_height, 0)
|
|
|
+ win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
|
|
|
+ win32gui.SetForegroundWindow(hwnd)
|
|
|
+
|
|
|
+ return middle_point, base_width, base_height
|
|
|
+
|
|
|
+# arrange_windows()
|
|
|
+# Example usage:
|
|
|
+# Assume chrome_hwnds is a list of Chrome window handles
|
|
|
+
|
|
|
+# win32gui.SetWindowPos(chromeHwnd,win32con.HWND_TOP,0,0,800,800,0)
|
|
|
+# win32gui.ShowWindow(chromeHwnd, win32con.SW_MAXIMIZE) # 确保窗口处于正常状态
|
|
|
+# win32gui.SetForegroundWindow(chromeHwnd)
|
|
|
+
|
|
|
+# 获取当前鼠标位置
|
|
|
+# original_position = target.position
|
|
|
+#
|
|
|
+# # 移动鼠标到新位置(相对当前位置)
|
|
|
+# new_position = (original_position[0] + 100, original_position[1] + 100)
|
|
|
+# target.position = new_position
|
|
|
+#
|
|
|
+# # 可以使用动作链进行平滑的移动
|
|
|
+# target.move(0, 1)
|
|
|
+#
|
|
|
+# # 休眠几秒钟,你可以根据需要调整
|
|
|
+# time.sleep(2)
|
|
|
+
|
|
|
+# target.position = (1,1)
|