Add: Global shortcut to take screenshots

This commit is contained in:
LmeSzinc 2023-09-11 19:26:13 +08:00
parent 66837083c2
commit 2c58bb4f83
3 changed files with 28 additions and 5 deletions

View File

@ -3,6 +3,7 @@ from datetime import datetime
from PIL import Image
from pynput import keyboard
from module.config.config import AzurLaneConfig
from module.config.utils import alas_instance
from module.device.connection import Connection, ConnectionAttr
@ -66,22 +67,42 @@ else:
config.override(
Emulator_Serial=name,
Emulator_PackageName='com.miHoYo.hkrpg',
ScreenshotMethod='ADB_nc',
Emulator_ScreenshotMethod='adb_nc',
)
device = Device(config)
output = './screenshots/dev_screenshots'
os.makedirs(output, exist_ok=True)
device.disable_stuck_detection()
device.screenshot_interval_set(0.)
print('')
print(f'截图将保存到: {output}')
while 1:
print()
_ = input('按回车键截一张图:')
def screenshot():
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)
print(f'截图中...')
Image.fromarray(image).save(file)
print(f'截图已保存到: {file}')
# 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()

View File

@ -36,3 +36,4 @@ srcmap==1.1.0
# For dev
# pip-tools
pynput

View File

@ -50,6 +50,7 @@ pyclipper==1.3.0.post4 # via pponnxcr
pydantic==1.10.7 # via -r requirements-in.txt
pyelftools==0.29 # via apkutils2
pygments==2.15.1 # via rich
pynput==1.7.6 # via -r requirements-in.txt
pyparsing==3.0.9 # via packaging
pyreadline3==3.4.1 # via humanfriendly
python-dotenv==1.0.0 # via uvicorn
@ -60,7 +61,7 @@ retry==0.9.2 # via adbutils, uiautomator2
rich==13.3.5 # via -r requirements-in.txt
scipy==1.10.1 # via -r requirements-in.txt
shapely==2.0.1 # via pponnxcr
six==1.16.0 # via uiautomator2
six==1.16.0 # via pynput, uiautomator2
sniffio==1.3.0 # via anyio
srcmap==1.1.0 # via -r requirements-in.txt
starlette==0.14.2 # via -r requirements-in.txt