跳到正文
所有工具

ui_keystroke

屏幕、窗口与界面 · macOS · Windows

效果: 执行. 状态: 受限可用.

“受限可用”表示工具可能取决于版本、平台、权限、账户或配置,并不表示它在所有安装中都已启用。

macOS

用途

发送组合键,例如“cmd+shift+5”“return”“cmd+,”“escape”。修饰键:cmd、shift、alt/option、ctrl、fn;最后一个标记是按键。返回 {sent, delivery:"posted_not_confirmed"};`sent` 只表示按键事件已发出,不表示应用已执行操作:CGEvent 不提供投递确认,而且按键效果可以是任意行为,无法通过回读证明。应使用 ui_get_element / ui_read_tree 确认效果,不要信任 `sent`。组合键完成后会释放修饰键,因此后续 ui_type 不会被吞掉。无法识别按键时返回 unknown_key。需要辅助功能权限。(原样保留的字面值:'return'、'cmd+,'。)

必填输入

输入名称会严格保持工具要求的形式。下方可展开的架构中保留英文规范技术定义。

权限与确认

架构未声明明确的确认参数。这并不代表可以未经许可操作;请检查效果并取得授权。

英文规范技术架构 — macOS
{
  "properties": {
    "keys": {
      "description": "e.g. cmd+shift+5, return, cmd+,",
      "type": "string"
    }
  },
  "required": [
    "keys"
  ],
  "type": "object"
}

文档示例

ui_keystroke 的文档示例。请勿执行此示例。所示参数属于虚构数据集;在实际调用前,请解析真实标识符并获得授权。

{
  "keys": "escape"
}

Windows

用途

发送组合键,例如 "ctrl+s"、"ctrl+shift+n"、"return"、"alt+f4"、"escape"。修饰键:ctrl、shift、alt、win(接受 cmd 作为 ctrl 的别名)。最后一个标记是按键。无法识别按键时返回 unknown_key。传入 element_ref 可指向某个元素(会先使其获得焦点);不传时,按键会发送到当前聚焦的应用,并在 sent_to 中报告。

必填输入

输入名称会严格保持工具要求的形式。下方可展开的架构中保留英文规范技术定义。

权限与确认

架构未声明明确的确认参数。这并不代表可以未经许可操作;请检查效果并取得授权。

英文规范技术架构 — Windows
{
  "properties": {
    "element_ref": {
      "description": "Optional. Focus this element (from ui_find_element) before sending; refused with focus_failed, nothing sent, if the focus does not land in its app or its app is not the window in front; focus_lost (with sent_to and target) when another window was in front after the keys. Without it the keys go to whatever has the focus — check sent_to.",
      "type": "string"
    },
    "keys": {
      "description": "e.g. ctrl+s, return, ctrl+shift+n",
      "type": "string"
    }
  },
  "required": [
    "keys"
  ],
  "type": "object"
}

文档示例

ui_keystroke 的文档示例。请勿执行此示例。所示参数属于虚构数据集;在实际调用前,请解析真实标识符并获得授权。

{
  "keys": "escape"
}