feat: support key combinations in press_key function and update related tests

This commit is contained in:
Space-Banane
2026-05-27 21:20:03 +02:00
parent 278f011a6d
commit 48a145d147
4 changed files with 69 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ class _DummyPyAutoGUI:
def __init__(self) -> None:
self.last_move_to: tuple[int, int] | None = None
self.last_click: tuple[int, int] | None = None
self.last_hotkey: tuple[str, ...] | None = None
def screenshot(self) -> Image.Image:
return Image.new("RGB", (1280, 720), color=(24, 24, 24))
@@ -35,6 +36,9 @@ class _DummyPyAutoGUI:
def press(self, _: str) -> None:
return None
def hotkey(self, *keys: str) -> None:
self.last_hotkey = tuple(keys)
def _build_agent(tmp_path: Path, monkeypatch) -> agent_module.ScreenJobAgent:
dummy_gui = _DummyPyAutoGUI()
@@ -89,3 +93,12 @@ def test_click_supports_directional_offsets(tmp_path: Path, monkeypatch) -> None
)
assert click_result["ok"] is True
assert click_result["clicked"] == {"x": 110, "y": 102}
def test_press_key_supports_hotkey_combo(tmp_path: Path, monkeypatch) -> None:
agent = _build_agent(tmp_path, monkeypatch)
result = agent._tool_press_key({"key": "meta+r"})
assert result["ok"] is True
assert result["key"] == "win+r"
assert result["message"] == "Key combo executed."
assert agent_module.pyautogui.last_hotkey == ("win", "r")