diff --git a/README.md b/README.md index 3abb819..e1761be 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ -# GenshinImpact_Start \ No newline at end of file +## 简介 + +这是一个因为梗而创作的程序 + +**检测到你的屏幕白色占比超过90%那么将自动启动原神** + +来源于群友的一个视频@Tokeii0 + +
+ +## 本源码包含的技术 + +- 检测屏幕白色像素比例(cv2) +- 获取原神路径(原神没有把路径放入注册表,我通过获取快捷方式拼接的路径) +- 将原神窗口置顶 + +
+ +## 如何使用本源码 + +### 从源码使用: + +``` +git clone https://github.com/YinBuLiao/GenshinImpact_Start.git +cd GenshinImpact_Start +pip install requirements.txt +python main.py(需要使用管理员权限运行) +``` + +### 从release下载: + +- 将软件下载以后以管理员模式启动程序 + +## 特别感谢 + +- [Tokeii0](https://github.com/Tokeii0) diff --git a/main.py b/main.py new file mode 100644 index 0000000..db90dbc --- /dev/null +++ b/main.py @@ -0,0 +1,55 @@ +import cv2 +import pyautogui +import os +import time +import subprocess +import win32com.client +import numpy as np +from PIL import ImageGrab + +while True: + # 检查原神是否已经启动 + if os.system('tasklist /FI "IMAGENAME eq YuanShen.exe" 2>NUL | find /I /N "YuanShen.exe">NUL') == 0: + print("原神 已在运行!") + break + + # 获取屏幕分辨率 + screen_width, screen_height = pyautogui.size() + + # 截图 + print("正在检测屏幕...") + screenshot = cv2.cvtColor(np.array(ImageGrab.grab(bbox=(0,0,screen_width,screen_height))), cv2.COLOR_BGR2RGB) + + # 计算屏幕白色像素比例 + white_pixels = np.count_nonzero(screenshot == [255, 255, 255]) + total_pixels = screenshot.shape[0] * screenshot.shape[1] + white_percentage = white_pixels / total_pixels * 100 + + # 判断是否满足启动条件 + if white_percentage >= 90: + try: + # 获取快捷方式路径 + shortcut = r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\原神\原神.lnk' + + # 解析快捷方式获取安装路径 + shell = win32com.client.Dispatch("WScript.Shell") + install_dir = shell.CreateShortCut(shortcut) + install_dir = install_dir.TargetPath.replace('launcher.exe', '') + + + # 拼接游戏exe路径 + game_exe = os.path.join(install_dir, 'Genshin Impact Game', 'YuanShen.exe') + + # 将游戏置顶启动 + subprocess.Popen(game_exe) + # 枚举窗口,找到名称包含"原神"的窗口 + time.sleep(5) + window = pyautogui.getWindowsWithTitle("原神")[0] + + # 将目标窗口置顶 + pyautogui.moveTo(window.left, window.top) + print("原神 启动!") + break + except: + print("未获取到原神安装路径!或权限不够!") + break \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..737070b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +opencv-python +pyautogui +numpy +subprocess +win32api \ No newline at end of file