lc-mcp v0.5: 语义化操控(MCP stdio) — OCR文本化+语义点击, win/linux/mac 截图与输入后端

Browse Source
This commit is contained in:
yws
2026-10-01 16:37:33 +00:00
commit 0db14040b7
15 changed files with 1124 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
"""Linux X11 输入后端:xdotool(X 事件注入,xdotool 需已安装)。
物理化升级路径: uinput 后端(虚拟内核 evdev 设备)。
"""
import shutil
import subprocess
import time
def _run(args):
return subprocess.run(args, capture_output=True, text=True, timeout=30)
class XdotoolBackend:
def __init__(self):
if not shutil.which('xdotool'):
raise RuntimeError('xdotool not found (apt install xdotool)')
def _screen(self):
try:
r = _run(['xdotool', 'getdisplaygeometry'])
w, h = r.stdout.strip().split()
return int(w), int(h)
except Exception:
return 1920, 1080
def move(self, x, y):
_run(['xdotool', 'mousemove', str(int(x)), str(int(y))])
return {'ok': True}
def click(self, x, y, button='left', times=1):
btn = {'left': '1', 'right': '3', 'middle': '2'}.get(button, '1')
_run(['xdotool', 'mousemove', str(int(x)), str(int(y))])
_run(['xdotool', 'click', '--repeat', str(times), '--delay', '60', btn])
return {'ok': True}
def keypress(self, key):
key = key.lower()
# xdotool 键名映射
mapping = {'enter': 'Return', 'esc': 'Escape', 'space': 'space',
'tab': 'Tab', 'alt': 'Alt_L', 'f4': 'F4', 'ctrl': 'Control_L',
'shift': 'Shift_L', 'backspace': 'BackSpace'}
k = mapping.get(key, key)
_run(['xdotool', 'key', k])
return {'ok': True}
def type_text(self, text):
_run(['xdotool', 'type', '--delay', '60', text])
return {'ok': True}