lc-mcp v0.5: 语义化操控(MCP stdio) — OCR文本化+语义点击, win/linux/mac 截图与输入后端
This commit is contained in:
@@ -0,0 +1,58 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""平台抽象:截图 + 输入后端,按平台注册。
|
||||||
|
core (MCP协议/OCR/语义工具) 平台无关。"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def detect_platform():
|
||||||
|
p = os.environ.get('LCP_PLATFORM', '')
|
||||||
|
if p:
|
||||||
|
return p.lower()
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
return 'win'
|
||||||
|
if sys.platform == 'darwin':
|
||||||
|
return 'mac'
|
||||||
|
return 'linux'
|
||||||
|
|
||||||
|
|
||||||
|
def get_screenshot_provider(platform=None):
|
||||||
|
platform = platform or detect_platform()
|
||||||
|
if platform == 'win':
|
||||||
|
from .win import WinScreenshotProvider
|
||||||
|
return WinScreenshotProvider()
|
||||||
|
if platform == 'linux':
|
||||||
|
from .linux import LinuxScreenshotProvider
|
||||||
|
return LinuxScreenshotProvider()
|
||||||
|
if platform == 'mac':
|
||||||
|
from .mac import MacScreenshotProvider
|
||||||
|
return MacScreenshotProvider()
|
||||||
|
raise ValueError('no screenshot provider for %s' % platform)
|
||||||
|
|
||||||
|
|
||||||
|
def get_input_backend(name=None, platform=None):
|
||||||
|
platform = platform or detect_platform()
|
||||||
|
name = (name or os.environ.get('INPUT_BACKEND', '') or
|
||||||
|
{'win': 'sendinput', 'linux': 'xdotool', 'mac': 'cg'}[platform]).lower()
|
||||||
|
if name == 'mock':
|
||||||
|
from backends.mock import MockBackend
|
||||||
|
return MockBackend()
|
||||||
|
if platform == 'win':
|
||||||
|
if name == 'sendinput':
|
||||||
|
from backends.sendinput_win import SendInputBackend
|
||||||
|
return SendInputBackend()
|
||||||
|
if name == 'interception':
|
||||||
|
from backends.interception_win import InterceptionBackend
|
||||||
|
return InterceptionBackend()
|
||||||
|
if platform == 'linux':
|
||||||
|
if name == 'xdotool':
|
||||||
|
from backends.xdotool_linux import XdotoolBackend
|
||||||
|
return XdotoolBackend()
|
||||||
|
if name == 'uinput':
|
||||||
|
from backends.uinput_linux import UinputBackend
|
||||||
|
return UinputBackend()
|
||||||
|
if platform == 'mac' and name == 'cg':
|
||||||
|
from backends.cg_mac import CGBackend
|
||||||
|
return CGBackend()
|
||||||
|
raise ValueError('no input backend %s for %s' % (name, platform))
|
||||||
Reference in New Issue
Block a user