2023-05-16 15:38:03 +00:00
|
|
|
|
import os
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
2023-09-11 11:26:13 +00:00
|
|
|
|
from pynput import keyboard
|
2023-05-16 15:38:03 +00:00
|
|
|
|
from module.config.config import AzurLaneConfig
|
|
|
|
|
from module.config.utils import alas_instance
|
|
|
|
|
from module.device.connection import Connection, ConnectionAttr
|
|
|
|
|
from module.device.device import Device
|
|
|
|
|
from module.logger import logger
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
A tool to take screenshots on device
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
python -m dev_tools.screenshot
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmptyConnection(Connection):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
ConnectionAttr.__init__(self, AzurLaneConfig('template'))
|
|
|
|
|
|
|
|
|
|
logger.hr('Detect device')
|
|
|
|
|
print()
|
|
|
|
|
print('这里是你本机可用的模拟器serial:')
|
|
|
|
|
devices = self.list_device()
|
|
|
|
|
|
|
|
|
|
# Show available devices
|
|
|
|
|
available = devices.select(status='device')
|
|
|
|
|
for device in available:
|
|
|
|
|
print(device.serial)
|
|
|
|
|
if not len(available):
|
|
|
|
|
print('No available devices')
|
|
|
|
|
|
|
|
|
|
# Show unavailable devices if having any
|
|
|
|
|
unavailable = devices.delete(available)
|
|
|
|
|
if len(unavailable):
|
|
|
|
|
print('Here are the devices detected but unavailable')
|
|
|
|
|
for device in unavailable:
|
|
|
|
|
print(f'{device.serial} ({device.status})')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_sensitive_info(image):
|
|
|
|
|
# Paint UID to black
|
|
|
|
|
image[680:720, 0:180, :] = 0
|
|
|
|
|
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_ = EmptyConnection()
|
|
|
|
|
name = input(
|
2024-02-29 15:01:29 +00:00
|
|
|
|
'输入src配置文件名称,或者模拟器serial,或者模拟器端口号: (默认输入 "src"):\n'
|
|
|
|
|
'例如:"src", "127.0.0.1:16384", "7555"\n'
|
2023-05-16 15:38:03 +00:00
|
|
|
|
)
|
|
|
|
|
name = name.strip().strip('"').strip()
|
|
|
|
|
if not name:
|
2024-02-29 15:01:29 +00:00
|
|
|
|
name = 'src'
|
2023-05-16 15:38:03 +00:00
|
|
|
|
if name.isdigit():
|
|
|
|
|
name = f'127.0.0.1:{name}'
|
|
|
|
|
if name in alas_instance():
|
|
|
|
|
print(f'{name} is an existing config file')
|
|
|
|
|
device = Device(name)
|
|
|
|
|
else:
|
|
|
|
|
print(f'{name} is a device serial')
|
|
|
|
|
config = AzurLaneConfig('template')
|
|
|
|
|
config.override(
|
|
|
|
|
Emulator_Serial=name,
|
|
|
|
|
Emulator_PackageName='com.miHoYo.hkrpg',
|
2023-09-11 11:26:13 +00:00
|
|
|
|
Emulator_ScreenshotMethod='adb_nc',
|
2023-05-16 15:38:03 +00:00
|
|
|
|
)
|
|
|
|
|
device = Device(config)
|
|
|
|
|
|
|
|
|
|
output = './screenshots/dev_screenshots'
|
|
|
|
|
os.makedirs(output, exist_ok=True)
|
|
|
|
|
device.disable_stuck_detection()
|
2023-09-11 11:26:13 +00:00
|
|
|
|
device.screenshot_interval_set(0.)
|
2023-05-16 15:38:03 +00:00
|
|
|
|
print('')
|
|
|
|
|
print(f'截图将保存到: {output}')
|
2023-09-11 11:26:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def screenshot():
|
2023-05-16 15:38:03 +00:00
|
|
|
|
print(f'截图中...')
|
|
|
|
|
image = device.screenshot()
|
|
|
|
|
now = datetime.strftime(datetime.now(), '%Y-%m-%d_%H-%M-%S-%f')
|
|
|
|
|
file = f'{output}/{now}.png'
|
|
|
|
|
image = handle_sensitive_info(image)
|
2023-09-11 11:26:13 +00:00
|
|
|
|
print(f'截图中...')
|
2023-05-16 15:38:03 +00:00
|
|
|
|
Image.fromarray(image).save(file)
|
|
|
|
|
print(f'截图已保存到: {file}')
|
2023-09-11 11:26:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bind global shortcut
|
|
|
|
|
GLOBAL_KEY = 'F3'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_press(key):
|
|
|
|
|
if str(key) == f'Key.{GLOBAL_KEY.lower()}':
|
|
|
|
|
screenshot()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listener = keyboard.Listener(on_press=on_press)
|
|
|
|
|
listener.start()
|
|
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
|
print()
|
|
|
|
|
_ = input(f'按 <回车键> 或者按快捷键 <{GLOBAL_KEY}> 截一张图(快捷键全局生效):')
|
|
|
|
|
screenshot()
|