fixed hotkey parsing and double click bugs

This commit is contained in:
Dillon DuPont
2025-04-17 18:42:40 -04:00
parent 3e3a482cc8
commit 196f92617d
2 changed files with 37 additions and 5 deletions

View File

@@ -542,7 +542,7 @@ class MacOSAutomationHandler(BaseAutomationHandler):
try:
if x is not None and y is not None:
pyautogui.moveTo(x, y)
pyautogui.doubleClick()
pyautogui.doubleClick(interval=0.1)
return {"success": True}
except Exception as e:
return {"success": False, "error": str(e)}

View File

@@ -377,17 +377,49 @@ class MacOSComputerInterface(BaseComputerInterface):
"""
await self.press(key)
async def hotkey(self, *keys: str) -> None:
await self._send_command("hotkey", {"keys": list(keys)})
async def hotkey(self, *keys: "KeyType") -> None:
"""Press multiple keys simultaneously.
Args:
*keys: Multiple keys to press simultaneously. Each key can be any of:
- A Key enum value (recommended), e.g. Key.COMMAND
- A direct key value string, e.g. 'command'
- A single character string, e.g. 'a'
Examples:
```python
# Using enums (recommended)
await interface.hotkey(Key.COMMAND, Key.C) # Copy
await interface.hotkey(Key.COMMAND, Key.V) # Paste
# Using mixed formats
await interface.hotkey(Key.COMMAND, 'a') # Select all
```
Raises:
ValueError: If any key type is invalid or not recognized
"""
actual_keys = []
for key in keys:
if isinstance(key, Key):
actual_keys.append(key.value)
elif isinstance(key, str):
# Try to convert to enum if it matches a known key
key_or_enum = Key.from_string(key)
actual_keys.append(key_or_enum.value if isinstance(key_or_enum, Key) else key_or_enum)
else:
raise ValueError(f"Invalid key type: {type(key)}. Must be Key enum or string.")
await self._send_command("hotkey", {"keys": actual_keys})
# Scrolling Actions
async def scroll_down(self, clicks: int = 1) -> None:
for _ in range(clicks):
await self.hotkey("pagedown")
await self.hotkey(Key.PAGE_DOWN)
async def scroll_up(self, clicks: int = 1) -> None:
for _ in range(clicks):
await self.hotkey("pageup")
await self.hotkey(Key.PAGE_UP)
# Screen Actions
async def screenshot(