| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from __future__ import annotations
- from typing import Any
- from ... import windows_automation
- from ..context import WorkflowContext
- from ..registry import control_ports, field_def, register_node
- MEDIA_KEY_MAP = {
- "play_pause": "space",
- "site_fullscreen": "f",
- "mute": "m",
- "volume_up": "volumeup",
- "volume_down": "volumedown",
- "system_mute": "volumemute",
- "next": "down",
- "previous": "up",
- "escape": "escape",
- }
- def media_control_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
- params = node.get("params", {})
- action = str(inputs.get("action", params.get("action")) or "play_pause")
- key = MEDIA_KEY_MAP.get(action, "space")
- result = windows_automation.keyboard_action("press", key=key)
- return {"action": action, "key": key, "keyboard": result}
- register_node(
- {
- "type": "media.control",
- "category": "media",
- "label": "媒体遥控",
- "description": "对当前播放页面执行播放暂停、网页全屏、静音、音量和上下条等客厅遥控动作。",
- "params": {
- "action": field_def(
- "select",
- "动作",
- "play_pause",
- options=[
- "play_pause",
- "site_fullscreen",
- "mute",
- "volume_up",
- "volume_down",
- "system_mute",
- "next",
- "previous",
- "escape",
- ],
- )
- },
- "inputs": {"action": field_def("string", "动作")},
- "outputs": {
- "action": {"type": "string", "label": "动作"},
- "key": {"type": "string", "label": "按键"},
- "keyboard": {"type": "object", "label": "键盘结果"},
- },
- "control_ports": control_ports(),
- },
- media_control_node,
- )
|