diff --git a/README.md b/README.md index d1ed24a580ec745dedca3ea9d45746563e5e1c85..d8971eaf0bedc2e694da9c618f1e2e19c1781285 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Windows-optimization [![star](https://gitee.com/LZY4/Windows-optimization/badge/star.svg?theme=dark)](https://gitee.com/LZY4/Windows-optimization/stargazers) [![GitHub](https://img.shields.io/github/stars/cnlnr/Windows-optimization)](https://github.com/cnlnr/Windows-optimization) -此项目专门用于 Windows 系统的优化 [![bilibili-演示](https://img.shields.io/badge/bilibili-演示-FB7299?logo=bilibili&logoColor=00A1D6)](https://b23.tv/fNLKMBE) +此项目专门用于 Windows11 系统的优化 [![bilibili-演示](https://img.shields.io/badge/bilibili-演示-FB7299?logo=bilibili&logoColor=00A1D6)](https://b23.tv/fNLKMBE) ## 安装 diff --git a/demo.xls b/demo.xls new file mode 100644 index 0000000000000000000000000000000000000000..dd5e863d6dfe237a20e7f408953744a1349ea704 Binary files /dev/null and b/demo.xls differ diff --git a/main1.py b/main1.py new file mode 100644 index 0000000000000000000000000000000000000000..b22f1581be126948bdc0eeb3781b56bc713ab5d9 --- /dev/null +++ b/main1.py @@ -0,0 +1,42 @@ +import ctypes +import psutil + +kernel32 = ctypes.windll.kernel32 + +class MEMORY_BASIC_INFORMATION(ctypes.Structure): + _fields_ = [ + ("BaseAddress", ctypes.c_void_p), + ("AllocationBase", ctypes.c_void_p), + ("AllocationProtect", ctypes.c_ulong), + ("RegionSize", ctypes.c_size_t), + ("State", ctypes.c_ulong), + ("Protect", ctypes.c_ulong), + ("Type", ctypes.c_ulong), + ] + + +def check_memory(pid, address): + h_process = kernel32.OpenProcess(0x10, False, pid) + mbi = MEMORY_BASIC_INFORMATION() + + res = kernel32.VirtualQueryEx( + h_process, + ctypes.c_void_p(address), + ctypes.byref(mbi), + ctypes.sizeof(mbi) + ) + + if res: + print("内存基址:", hex(mbi.BaseAddress)) + print("保护属性 Protect:", hex(mbi.Protect)) + print("类型 Type:", hex(mbi.Type)) + else: + print("查询失败") + + kernel32.CloseHandle(h_process) + + +# 调用 +pid = 13500 +addr = 0x15F75FC3244 +check_memory(pid, addr) \ No newline at end of file diff --git a/mian.py b/mian.py deleted file mode 100644 index fa46ef3bede01ad9aeb4399024c8b84cc6337a3c..0000000000000000000000000000000000000000 --- a/mian.py +++ /dev/null @@ -1,46 +0,0 @@ -from pynput import keyboard -from pynput.keyboard import Key, KeyCode, Controller - -# 初始化键盘控制器,用于模拟按键操作 -keyboard_ctrl = Controller() -# 记录已按下的键,避免长按重复触发 -pressed_keys = set() - -def on_press(key): - """按键按下时的回调函数""" - # 避免重复触发:已按下的键不再处理 - if key in pressed_keys: - return - pressed_keys.add(key) - - # 退出逻辑:按 Esc 键停止监听 - if key == Key.esc: - print("已按下 Esc,程序退出") - return False # 返回 False 终止监听器 - - # 仅处理英文字母(区分大小写) - try: - char = key.char - if char.isalpha(): - print(f"检测到字母: {char},模拟按下并释放单引号(')键") - # 模拟按下单引号键 → 释放单引号键(完整的按键操作) - keyboard_ctrl.press("'") - keyboard_ctrl.release("'") - except AttributeError: - # 非字符键(如Ctrl、方向键等),不做处理 - pass - -def on_release(key): - """按键松开时的回调函数""" - # 从已按下集合中移除,恢复可触发状态 - if key in pressed_keys: - pressed_keys.remove(key) - -if __name__ == "__main__": - print("程序已启动!") - print("功能:按任意英文字母键,自动模拟输入单引号(')") - print("退出:按 Esc 键\n") - - # 启动键盘监听器 - with keyboard.Listener(on_press=on_press, on_release=on_release) as listener: - listener.join() \ No newline at end of file diff --git "a/\345\267\246\344\270\212\350\247\222/\345\267\246\344\270\212\350\247\222.py" "b/\345\267\246\344\270\212\350\247\222/\345\267\246\344\270\212\350\247\222.py" index ffd9a79047f3244194cce5ebf94873f8f58fb7c4..fcbe41ef38d57ebb5f9a250e299e5e0f63426c89 100644 --- "a/\345\267\246\344\270\212\350\247\222/\345\267\246\344\270\212\350\247\222.py" +++ "b/\345\267\246\344\270\212\350\247\222/\345\267\246\344\270\212\350\247\222.py" @@ -14,9 +14,9 @@ while True: elif keyboard.is_pressed('alt'): keyboard.press_and_release('tab') else: - # keyboard.press_and_release('win + 1') + keyboard.press_and_release('win + 1') # 模拟gnome(win + tab)打开任务视图 - keyboard.press_and_release('win + tab') + # keyboard.press_and_release('win + tab') diff --git "a/\347\252\227\345\217\243\345\214\272\345\237\237\346\211\251\345\261\225/all_windows_hwnd.py" "b/\347\252\227\345\217\243\345\214\272\345\237\237\346\211\251\345\261\225/all_windows_hwnd.py" new file mode 100644 index 0000000000000000000000000000000000000000..e759e667de3a9ee5ebfba980e0a3f757d007d257 --- /dev/null +++ "b/\347\252\227\345\217\243\345\214\272\345\237\237\346\211\251\345\261\225/all_windows_hwnd.py" @@ -0,0 +1,29 @@ +import comtypes.client +import win32gui +import win32process +import win32api +import psutil + +def get_taskbar_app_process(): + uia = comtypes.client.CreateObject("UIAutomationClient.CUIAutomation") + x, y = win32api.GetCursorPos() + + element = uia.ElementFromPoint((x, y)) + if not element: + return None + + name = element.CurrentName + if not name: + return None + + # 枚举所有顶级窗口,匹配标题 + result = [] + def enum(hwnd, _): + title = win32gui.GetWindowText(hwnd) + if name in title: + result.append(hwnd) + win32gui.EnumWindows(enum, None) + + return result + +print(get_taskbar_app_process()) \ No newline at end of file diff --git "a/\351\274\240\346\240\207\346\211\213\345\212\277/cursor_direction.py" "b/\351\274\240\346\240\207\346\211\213\345\212\277/cursor_direction.py" new file mode 100644 index 0000000000000000000000000000000000000000..b53439c313214aec6d54d17247a405e7dd1c268e --- /dev/null +++ "b/\351\274\240\346\240\207\346\211\213\345\212\277/cursor_direction.py" @@ -0,0 +1,92 @@ +import time +import pyautogui +import math +import ctypes + +def calculate_cumulative_movement(sample_interval=0.01, duration=0.2): + """ + 计算指定时长内鼠标的累计移动距离和主方向 + sample_interval: 采样间隔(越小越精准,但占用资源略高) + duration: 总检测时长 + """ + # 初始化变量 + total_distance = 0 # 累计移动距离 + prev_x, prev_y = pyautogui.position() # 上一个采样点坐标 + total_dx = 0 # 累计x轴位移(右正左负) + total_dy = 0 # 累计y轴位移(下正上负) + + # 计算需要采样的次数 + sample_count = int(duration / sample_interval) + + for _ in range(sample_count): + time.sleep(sample_interval) + curr_x, curr_y = pyautogui.position() + + # 计算当前采样点与上一个采样点的欧氏距离(真实移动距离) + dx = curr_x - prev_x + dy = curr_y - prev_y + distance = math.hypot(dx, dy) # 等价于sqrt(dx² + dy²) + + # 累加距离和位移 + total_distance += distance + total_dx += dx + total_dy += dy + + # 更新上一个采样点坐标 + prev_x, prev_y = curr_x, curr_y + + # 确定主移动方向 + moves = { + "Right": max(total_dx, 0), + "Left": max(-total_dx, 0), + "Down": max(total_dy, 0), + "Up": max(-total_dy, 0), + } + main_direction = max(moves, key=moves.get) + + return main_direction, total_distance + +def wait_for_large_movement(up_th=350, down_th=400, left_th=500, right_th=550, + sample_interval=0.002, duration=0.03): + """ + 循环检测鼠标累计移动,超过阈值时返回方向 + 解决了"移动后回原点"导致的误判问题 + """ + while True: + direction, total_distance = calculate_cumulative_movement(sample_interval, duration) + + # 判断是否超过对应方向的阈值 + if direction == "Up" and total_distance > up_th: + return "Up" + if direction == "Down" and total_distance > down_th: + return "Down" + if direction == "Left" and total_distance > left_th: + return "Left" + if direction == "Right" and total_distance > right_th: + return "Right" + + +# 鼠标按键代码 +VK_LBUTTON = 0x01 # 左键 +VK_RBUTTON = 0x02 # 右键 +VK_MBUTTON = 0x04 # 中键 + +def is_mouse_pressed() -> bool: + """ + 检测鼠标任意键(左/中/右)是否按下 + 返回: True/False + """ + left = ctypes.windll.user32.GetAsyncKeyState(VK_LBUTTON) & 0x8000 != 0 + right = ctypes.windll.user32.GetAsyncKeyState(VK_RBUTTON) & 0x8000 != 0 + middle = ctypes.windll.user32.GetAsyncKeyState(VK_MBUTTON) & 0x8000 != 0 + return left or right or middle + + +if __name__ == "__main__": + print("开始检测鼠标大幅移动...") + print("提示:采样间隔0.01s,检测时长0.2s,可根据需要调整参数") + while True: + result = wait_for_large_movement() + print("触发方向:", result) + print("鼠标点击状态:", "按下" if is_mouse_pressed() else "未按") + time.sleep(0.4) \ No newline at end of file diff --git "a/\351\274\240\346\240\207\346\211\213\345\212\277/main.py" "b/\351\274\240\346\240\207\346\211\213\345\212\277/main.py" new file mode 100644 index 0000000000000000000000000000000000000000..3ff67ba60a153963331a9eedbc5326accd7236ab --- /dev/null +++ "b/\351\274\240\346\240\207\346\211\213\345\212\277/main.py" @@ -0,0 +1,22 @@ +import cursor_direction +import time +import keyboard + + +while True: + result = cursor_direction.wait_for_large_movement() + if cursor_direction.is_mouse_pressed(): + continue # 如果鼠标按钮被按下,跳过本次检测 + if result == "Right": + keyboard.press_and_release('ctrl + win + right') + elif result == "Left": + keyboard.press_and_release('ctrl + win + left') + elif result == "Up": + keyboard.press_and_release('win + tab') + time.sleep(0.4) + +""" 提示 +alt + esc 切换窗口 +alt + shift + esc 反向切换窗口 +win + d 显示桌面 +""" \ No newline at end of file