Skip to content

Commit 869c95b

Browse files
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
1 parent ece647b commit 869c95b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: examples/tools/computer_use.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ async def move(self, x: int, y: int) -> None:
148148
await self.page.mouse.move(x, y)
149149

150150
async def keypress(self, keys: list[str]) -> None:
151-
for key in keys:
152-
mapped_key = CUA_KEY_TO_PLAYWRIGHT_KEY.get(key.lower(), key)
153-
await self.page.keyboard.press(mapped_key)
151+
mapped_keys = [CUA_KEY_TO_PLAYWRIGHT_KEY.get(key.lower(), key) for key in keys]
152+
for key in mapped_keys:
153+
await self.page.keyboard.down(key)
154+
for key in reversed(mapped_keys):
155+
await self.page.keyboard.up(key)
154156

155157
async def drag(self, path: list[tuple[int, int]]) -> None:
156158
if not path:

0 commit comments

Comments
 (0)