hel 1 yıl önce
işleme
5ad34b8029

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 7 - 0
.idea/misc.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Black">
+    <option name="sdkName" value="Python 3.9 (python)" />
+  </component>
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (python)" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/python.iml" filepath="$PROJECT_DIR$/.idea/python.iml" />
+    </modules>
+  </component>
+</project>

+ 10 - 0
.idea/python.iml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/venv" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 75 - 0
listenTest.py

@@ -0,0 +1,75 @@
+import time
+
+from pynput import mouse
+from pynput.mouse import Controller, Button
+import asyncio
+
+import win32Test
+
+mouse_controller = Controller()
+
+middle_point, base_width, base_height = win32Test.arrange_windows()
+print(middle_point)
+print(base_width)
+print(base_height)
+
+
+def in_monitorZone():
+    now_position = mouse_controller.position
+    if now_position < (base_width, base_height):
+        return True
+    else:
+        return False
+
+
+def on_move(x, y):
+    return
+    # print('Pointer moved to {0}'.format(
+    #     (x, y)))
+
+
+def on_click(x, y, button, pressed):
+    print('{0} at {1}'.format(
+        'Pressed' if pressed else 'Released',
+        (x, y)))
+    print(button)
+    # if not pressed:
+    #     # Stop listener
+    #     return False
+
+
+async def scroll_to_next_point(middle_point, mouse_controller, dx, dy):
+    for i in range(1, len(middle_point)):
+        print('Scrolled to next point')
+        mouse_controller.position = middle_point[i]
+        await asyncio.sleep(1)
+        mouse_controller.scroll(dx, dy)
+
+
+def on_scroll(x, y, dx, dy):
+    print('Scrolled {0} at {1}'.format(
+        'down' if dy < 0 else 'up',
+        (x, y)))
+    if in_monitorZone():
+        origin = mouse_controller.position
+        for i in range(1, len(middle_point)):
+            print('scrolled')
+            mouse_controller.position = middle_point[i]
+            mouse_controller.click(Button.right, 1)
+            time.sleep(0.5)
+        mouse_controller.position = origin
+
+
+# Collect events until released
+with mouse.Listener(
+        on_move=on_move,
+        on_click=on_click,
+        on_scroll=on_scroll) as listener:
+    listener.join()
+
+# ...or, in a non-blocking fashion:
+listener = mouse.Listener(
+    on_move=on_move,
+    on_click=on_click,
+    on_scroll=on_scroll)
+listener.start()

+ 30 - 0
main.py

@@ -0,0 +1,30 @@
+# This is a sample Python script.
+
+from pynput import mouse,keyboard
+# Press Shift+F10 to execute it or replace it with your code.
+# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
+import win32con
+
+def on_press(key):
+    try:
+        print(f'Key {key.char} pressed')
+    except AttributeError:
+        print(f'Special key {key} pressed')
+
+def on_release(key):
+    if key == keyboard.Key.esc:
+        # Stop listener
+        return False
+
+def on_click(x, y, button, pressed):
+    if pressed:
+        print(f'Mouse clicked at ({x}, {y}) with {button}')
+
+# 鼠标监听
+mouse_listener = mouse.Listener(on_click=on_click)
+mouse_listener.start()
+
+# 键盘监听
+
+# 保持监听
+mouse_listener.join()

+ 8 - 0
monitorTest.py

@@ -0,0 +1,8 @@
+import time
+
+from pynput import mouse
+from pynput.mouse import Controller, Button
+import asyncio
+
+import win32Test
+

+ 80 - 0
win32Test.py

@@ -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)