From 869c95b012b242ba1333ae01113ba8e1cc54a70b Mon Sep 17 00:00:00 2001 From: kanchi <17161397+KanchiShimono@users.noreply.github.com> Date: Wed, 9 Apr 2025 00:47:15 +0900 Subject: [PATCH] Update `computer-use` example to support simultaneous key presses (#452) ### Summary Updated the `computer-use` example to support simultaneous key presses. The current implementation presses and releases keys one at a time, which prevents combo inputs like copy (CTRL+C) from working correctly. ### Test plan N/A ### Issue number N/A ### Checks - [ ] I've added new tests (if relevant) - [ ] I've added/updated the relevant documentation - [x] I've run `make lint` and `make format` - [ ] I've made sure tests pass --- examples/tools/computer_use.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/tools/computer_use.py b/examples/tools/computer_use.py index 832255e..0c17cf9 100644 --- a/examples/tools/computer_use.py +++ b/examples/tools/computer_use.py @@ -148,9 +148,11 @@ class LocalPlaywrightComputer(AsyncComputer): await self.page.mouse.move(x, y) async def keypress(self, keys: list[str]) -> None: - for key in keys: - mapped_key = CUA_KEY_TO_PLAYWRIGHT_KEY.get(key.lower(), key) - await self.page.keyboard.press(mapped_key) + mapped_keys = [CUA_KEY_TO_PLAYWRIGHT_KEY.get(key.lower(), key) for key in keys] + for key in mapped_keys: + await self.page.keyboard.down(key) + for key in reversed(mapped_keys): + await self.page.keyboard.up(key) async def drag(self, path: list[tuple[int, int]]) -> None: if not path: