更新时间:2026-08-05 GMT+08:00
分享

键盘控制概述

请在本地hw_r2c_sdk-x.x.x/r2c_sdk_python/config文件夹找到机器人配置文件robot_{不同的机器人}_config.yaml,比如robot_flexiv_config.yaml,机器人配置中包含键盘控制。

键盘控制通过stdin轮询实现机器人控制,仅在终端窗口有键盘焦点时响应按键,支持Linux(X11/Wayland/TTY)、macOS、Windows。

架构组件

表1 架构组件

模块

职责

KeyboardController

stdin轮询 + 命令分派

KeyboardCommandMapper

按键 与命令名映射(支持merge + 大小写fallback)

SyncRobotClient

注入pause/stop回调

核心特性

  • 焦点感知:仅终端有焦点时响应,全局无干扰
  • 零依赖:纯Python stdlib(sys.stdin + select/msvcrt)
  • 跨平台:Linux(X11/Wayland/TTY)、macOS、Windows统一
  • 安全门控:命令可选择“暂停态才执行”,防止运动中误触
  • 大小写不敏感:按j或J都匹配

平台兼容性

表2 平台兼容性

平台

终端

实现

终端恢复

Linux X11

GNOME Terminal / Konsole

os.read(fd) + select + tty.setcbreak

Linux Wayland

同上

同上

Linux TTY

纯终端

同上

macOS

Terminal.app / iTerm2

同上

Windows

cmd / PowerShell / Windows Terminal

msvcrt.kbhit() + getwch()

无需

相关文档