├── README.md ├── auto-music4k.py ├── auto-music(2560×1600).py ├── auto-music适配16:9全分辨率(只能全屏).py └── auto-music适配16:9全分辨率2(只能窗口化).py /README.md: -------------------------------------------------------------------------------- 1 | # genshin-auto-music 2 | 全自动完成原神类音乐游类活动(推荐使用bgi,bgi作者用c#重构了我的代码,适配更好,完成率更高占用更低:https://github.com/babalae/better-genshin-impact) 3 | 4 | 4k分辨率下的正确率在90%以上 5 | 6 | 为了满足部分分辨率会发布一些特殊分辨率版本 7 | 8 | 全适配脚本在90%以上 9 | 10 | 使用管理员运行时 按alt+x开始,按alt+v终止(貌似无法终止,有bug) 11 | 12 | 暂时窗口化和全屏是分开适配的 13 | 14 | 根据反馈静思浮梦完成率很高,关闭演出效果和辅助线,背景效果拉满 15 | 16 | 17 | 建议配置 18 | ![8c69f87053c011526bfc13dddcbfc7b8_720](https://github.com/DR-lin-eng/genshin-auto-music/assets/52230594/d9e4f595-aeea-4a7a-a3be-8fd7ae77d1f4) 19 | 20 | -------------------------------------------------------------------------------- /auto-music4k.py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time as t 3 | import pyautogui as p 4 | import keyboard 5 | 6 | keys = ['a', 's', 'd', 'j', 'k', 'l'] 7 | coords = [(832, 1838), (1268, 1838), (1698, 1838), (2128, 1838), (2564, 1838), (3000, 1838)] 8 | running = False 9 | 10 | def press_key(coord, key): 11 | while running: 12 | if p.pixel(coord[0], coord[1])[2] < 220: 13 | p.keyDown(key) 14 | while running and p.pixel(coord[0], coord[1])[2] < 220: 15 | t.sleep(0.005) # Minimize CPU usage, but effectively no "cooldown" between checks 16 | p.keyUp(key) 17 | 18 | def listen_for_stop(): 19 | global running 20 | keyboard.wait('alt+v') 21 | running = False 22 | 23 | def listen_for_start(): 24 | global running 25 | keyboard.wait('alt+x') 26 | running = True 27 | 28 | start_thread = threading.Thread(target=listen_for_start) 29 | start_thread.start() 30 | 31 | stop_thread = threading.Thread(target=listen_for_stop) 32 | stop_thread.start() 33 | 34 | threads = [] 35 | for coord, key in zip(coords, keys): 36 | thread = threading.Thread(target=press_key, args=(coord, key)) 37 | threads.append(thread) 38 | 39 | start_thread.join() 40 | 41 | for thread in threads: 42 | thread.start() 43 | 44 | for thread in threads: 45 | thread.join() 46 | 47 | stop_thread.join() 48 | -------------------------------------------------------------------------------- /auto-music(2560×1600).py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time as t 3 | import pyautogui as p 4 | import keyboard 5 | import logging 6 | 7 | logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') 8 | 9 | keys = ['a', 's', 'd', 'j', 'k', 'l'] 10 | coords = [(431, 1366), (772, 1366), (1108, 1366), (1444, 1366), (1789, 1366), (2115, 1366)] 11 | running = False 12 | 13 | def press_key(coord, key): 14 | while running: 15 | if p.pixel(coord[0], coord[1])[2] < 220: 16 | p.keyDown(key) 17 | while running and p.pixel(coord[0], coord[1])[2] < 220: 18 | t.sleep(0.00001) # Minimize CPU usage, but effectively no "cooldown" between checks 19 | p.keyUp(key) 20 | 21 | def listen_for_start(): 22 | global running 23 | keyboard.wait('alt+x') 24 | running = True 25 | 26 | def listen_for_stop(): 27 | global running 28 | keyboard.wait('alt+v') 29 | running = False 30 | 31 | start_thread = threading.Thread(target=listen_for_start) 32 | start_thread.start() 33 | 34 | stop_thread = threading.Thread(target=listen_for_stop) 35 | stop_thread.start() 36 | 37 | threads = [] 38 | for coord, key in zip(coords, keys): 39 | thread = threading.Thread(target=press_key, args=(coord, key)) 40 | threads.append(thread) 41 | 42 | start_thread.join() 43 | 44 | for thread in threads: 45 | thread.start() 46 | 47 | for thread in threads: 48 | thread.join() 49 | 50 | stop_thread.join() 51 | -------------------------------------------------------------------------------- /auto-music适配16:9全分辨率(只能全屏).py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time as t 3 | import pyautogui as p 4 | import keyboard 5 | 6 | 7 | base_resolution = (1920, 1080) 8 | base_coords = { 9 | 'a': (417, 916), 10 | 's': (632, 916), 11 | 'd': (846, 916), 12 | 'j': (1065, 916), 13 | 'k': (1282, 916), 14 | 'l': (1497, 916) 15 | } 16 | 17 | 18 | screen_width, screen_height = p.size() 19 | 20 | 21 | scale_x = screen_width / base_resolution[0] 22 | scale_y = screen_height / base_resolution[1] 23 | 24 | 25 | scaled_coords = {k: (int(v[0] * scale_x), int(v[1] * scale_y)) for k, v in base_coords.items()} 26 | keys = list(scaled_coords.keys()) 27 | coords = list(scaled_coords.values()) 28 | 29 | running = False 30 | 31 | def press_key(coord, key): 32 | while running: 33 | if p.pixel(coord[0], coord[1])[2] < 220: 34 | p.keyDown(key) 35 | while running and p.pixel(coord[0], coord[1])[2] < 220: 36 | t.sleep(0.002) 37 | p.keyUp(key) 38 | 39 | def listen_for_stop(): 40 | global running 41 | keyboard.wait('alt+v') 42 | running = False 43 | 44 | def listen_for_start(): 45 | global running 46 | keyboard.wait('alt+x') 47 | running = True 48 | 49 | start_thread = threading.Thread(target=listen_for_start) 50 | start_thread.start() 51 | 52 | stop_thread = threading.Thread(target=listen_for_stop) 53 | stop_thread.start() 54 | 55 | threads = [] 56 | for coord, key in zip(coords, keys): 57 | thread = threading.Thread(target=press_key, args=(coord, key)) 58 | threads.append(thread) 59 | 60 | start_thread.join() 61 | 62 | for thread in threads: 63 | thread.start() 64 | 65 | for thread in threads: 66 | thread.join() 67 | 68 | stop_thread.join() 69 | -------------------------------------------------------------------------------- /auto-music适配16:9全分辨率2(只能窗口化).py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time as t 3 | import pyautogui as p 4 | import keyboard 5 | import pygetwindow as gw 6 | 7 | # 基础分辨率和坐标 8 | base_resolution = (1920, 1080) 9 | base_coords = { 10 | 'a': (424, 916), 11 | 's': (638, 916), 12 | 'd': (851, 916), 13 | 'j': (1065, 916), 14 | 'k': (1282, 916), 15 | 'l': (1494, 916) 16 | } 17 | 18 | # 确保游戏窗口能被找到 19 | try: 20 | win = gw.getWindowsWithTitle('原神')[0] # 确保使用正确的窗口标题 21 | win.activate() 22 | win.moveTo(0, 0) 23 | win.resizeTo(base_resolution[0], base_resolution[1]) 24 | except IndexError: 25 | print("原神 window not found!") 26 | exit(1) 27 | 28 | # 将坐标调整到窗口位置 29 | left, top = win.topleft 30 | scaled_coords = {k: (left + int(v[0]), top + int(v[1])) for k, v in base_coords.items()} 31 | keys = list(scaled_coords.keys()) 32 | coords = list(scaled_coords.values()) 33 | 34 | # 控制变量 35 | running = False 36 | 37 | # 按键操作 38 | def press_key(coord, key): 39 | print(f"Thread for key {key} started.") 40 | while running: 41 | if p.pixel(coord[0], coord[1])[2] < 220: 42 | p.keyDown(key) 43 | while running and p.pixel(coord[0], coord[1])[2] < 220: 44 | t.sleep(0.002) 45 | p.keyUp(key) 46 | print(f"Thread for key {key} stopped.") 47 | 48 | # 监听停止和开始信号 49 | def listen_for_stop(): 50 | global running 51 | keyboard.wait('alt+v') 52 | running = False 53 | print("Stopping all threads...") 54 | 55 | def listen_for_start(): 56 | global running 57 | keyboard.wait('alt+x') 58 | running = True 59 | print("Starting all threads...") 60 | 61 | # 创建并启动线程 62 | def create_threads(): 63 | threads = [threading.Thread(target=press_key, args=(coord, key)) for coord, key in zip(coords, keys)] 64 | for thread in threads: 65 | thread.start() 66 | return threads 67 | 68 | # 主程序逻辑 69 | if __name__ == "__main__": 70 | start_thread = threading.Thread(target=listen_for_start) 71 | stop_thread = threading.Thread(target=listen_for_stop) 72 | 73 | start_thread.start() 74 | stop_thread.start() 75 | 76 | start_thread.join() # 等待开始信号 77 | 78 | if running: 79 | threads = create_threads() 80 | for thread in threads: 81 | thread.join() 82 | 83 | stop_thread.join() # 等待停止信号 --------------------------------------------------------------------------------