-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
# GenshinImpact_Start | ||
## 简介 | ||
|
||
这是一个因为梗而创作的程序 | ||
|
||
**检测到你的屏幕白色占比超过90%那么将自动启动原神** | ||
|
||
来源于群友的一个视频@Tokeii0 | ||
|
||
<br/> | ||
|
||
## 本源码包含的技术 | ||
|
||
- 检测屏幕白色像素比例(cv2) | ||
- 获取原神路径(原神没有把路径放入注册表,我通过获取快捷方式拼接的路径) | ||
- 将原神窗口置顶 | ||
|
||
<br/> | ||
|
||
## 如何使用本源码 | ||
|
||
### 从源码使用: | ||
|
||
``` | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
opencv-python | ||
pyautogui | ||
numpy | ||
subprocess | ||
win32api |