修复 v0.5 审查问题: platform 改名, 协议健壮性, CJK 匹配, VBS 引号, interception API
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""后端共用小工具。"""
|
||||
import ctypes
|
||||
|
||||
KEY_ALIASES = {'return': 'enter', 'escape': 'esc', 'del': 'delete', 'ins': 'insert',
|
||||
'pgup': 'pageup', 'pgdn': 'pagedown', 'control': 'ctrl', 'win': 'lwin',
|
||||
'arrowup': 'up', 'arrowdown': 'down', 'arrowleft': 'left', 'arrowright': 'right'}
|
||||
|
||||
|
||||
def parse_combo(key):
|
||||
"""'Alt+F4' -> ['alt', 'f4']; 单个 '+' 视为加号键。"""
|
||||
k = str(key).strip().lower()
|
||||
if k == '+' or '+' not in k:
|
||||
parts = [k]
|
||||
else:
|
||||
parts = [p.strip() for p in k.split('+')]
|
||||
if any(not p for p in parts):
|
||||
raise ValueError('bad key combo %r' % key)
|
||||
return [KEY_ALIASES.get(p, p) for p in parts]
|
||||
|
||||
|
||||
def win_dpi_aware(user32):
|
||||
"""声明 per-monitor DPI 感知, 让 SetCursorPos/GetSystemMetrics 用物理像素, 和截图一致。"""
|
||||
try:
|
||||
ctypes.windll.shcore.SetProcessDpiAwareness(2)
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
user32.SetProcessDPIAware()
|
||||
except Exception:
|
||||
pass
|
||||
Reference in New Issue
Block a user