| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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
- def press_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
- key = str(inputs.get("key", node.get("params", {}).get("key")) or "")
- result = windows_automation.keyboard_action("press", key=key)
- return {"key": result.get("key"), "action": result.get("action")}
- def hotkey_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
- keys = inputs.get("keys", node.get("params", {}).get("keys")) or []
- if isinstance(keys, str):
- keys = [part.strip() for part in keys.split("+") if part.strip()]
- result = windows_automation.keyboard_action("hotkey", keys=keys)
- return {"keys": result.get("keys"), "action": result.get("action")}
- def key_down_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
- key = str(inputs.get("key", node.get("params", {}).get("key")) or "")
- result = windows_automation.keyboard_action("key_down", key=key)
- return {"key": result.get("key"), "action": result.get("action")}
- def key_up_node(node: dict[str, Any], inputs: dict[str, Any], context: WorkflowContext) -> dict[str, Any]:
- key = str(inputs.get("key", node.get("params", {}).get("key")) or "")
- result = windows_automation.keyboard_action("key_up", key=key)
- return {"key": result.get("key"), "action": result.get("action")}
- KEY_OUTPUTS = {
- "key": {"type": "string", "label": "按键"},
- "keys": {"type": "array", "label": "组合键"},
- "action": {"type": "string", "label": "动作名称"},
- }
- for node_type, label, executor in [
- ("keyboard.press", "按下按键", press_node),
- ("keyboard.key_down", "按键按下", key_down_node),
- ("keyboard.key_up", "按键释放", key_up_node),
- ]:
- register_node(
- {
- "type": node_type,
- "category": "keyboard",
- "label": label,
- "params": {"key": field_def("text", "按键", required=True)},
- "inputs": {"key": field_def("string", "按键")},
- "outputs": KEY_OUTPUTS,
- "control_ports": control_ports(),
- },
- executor,
- )
- register_node(
- {
- "type": "keyboard.hotkey",
- "category": "keyboard",
- "label": "组合键",
- "params": {"keys": field_def("array", "组合键", ["ctrl", "s"], required=True)},
- "inputs": {"keys": field_def("array", "组合键")},
- "outputs": KEY_OUTPUTS,
- "control_ports": control_ports(),
- },
- hotkey_node,
- )
|