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
This commit is contained in:
kanchi 2025-04-09 00:47:15 +09:00 committed by GitHub
parent ece647b93f
commit 869c95b012
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: