2 changed files with 5 additions and 51 deletions
+5 -12
View File
@@ -6,7 +6,6 @@ import pyautogui
import subprocess
from io import BytesIO
from PIL import Image
import quartz_doubleclick
ANTHROPIC_API_URL = "https://api.anthropic.com/v1/messages"
MODEL = "claude-3-7-sonnet-20250219"
@@ -104,8 +103,7 @@ def execute_computer_tool(tool_input):
return {"type": "text", "text": "Error: Missing coordinates for double click action"}
# Perform double click
# pyautogui.doubleClick(x, y, interval=0.2) this doesn't work
quartz_doubleclick.double_click(x, y)
pyautogui.doubleClick(x, y, interval=0.2)
return {"type": "text", "text": f"Double-clicked at coordinates ({x}, {y})"}
elif action == "type":
@@ -116,17 +114,12 @@ def execute_computer_tool(tool_input):
elif action == "key":
# Press a key or key combination
text = tool_input.get("text", "")
key = tool_input.get("key", "")
try:
if '+' in text:
# Handle key combinations like "command+c"
keys = text.replace('super', 'command').split('+')
pyautogui.hotkey(*keys, interval=0.05) # interval is required
else:
pyautogui.press(text)
return {"type": "text", "text": f"Pressed key: {text}"}
pyautogui.press(key)
return {"type": "text", "text": f"Pressed key: {key}"}
except Exception as e:
return {"type": "text", "text": f"Error pressing key {text}: {str(e)}"}
return {"type": "text", "text": f"Error pressing key {key}: {str(e)}"}
elif action == "scroll":
# Scroll action
-39
View File
@@ -1,39 +0,0 @@
'''
This script simulates a double-click at the given mouse cursor position.
'''
import Quartz
from time import sleep
def post_mouse_event(type, pos, click_state):
event = Quartz.CGEventCreateMouseEvent(
None, type, pos, Quartz.kCGMouseButtonLeft
)
Quartz.CGEventSetIntegerValueField(event, Quartz.kCGMouseEventClickState, click_state)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
def double_click (x, y):
pos = None
if x is None or y is None:
# Get current mouse position if no coordinates are provided
loc = Quartz.CGEventGetLocation(Quartz.CGEventCreate(None))
pos = (loc.x, loc.y)
else:
# Use provided coordinates
pos = (x, y)
# First click
post_mouse_event(Quartz.kCGEventLeftMouseDown, pos, 1)
post_mouse_event(Quartz.kCGEventLeftMouseUp, pos, 1)
sleep(0.05) # Short delay within double-click threshold
# Second click
post_mouse_event(Quartz.kCGEventLeftMouseDown, pos, 2)
post_mouse_event(Quartz.kCGEventLeftMouseUp, pos, 2)
if __name__ == "__main__":
print('test: double clicking at cursor position in 3 seconds...')
sleep(3)
double_click()