remove kb focus func

This commit is contained in:
Dillon DuPont
2025-05-12 09:06:51 -04:00
parent a53c1a4476
commit 45b011db96
5 changed files with 0 additions and 97 deletions

View File

@@ -16,11 +16,6 @@ class BaseAccessibilityHandler(ABC):
"""Find an element in the accessibility tree by criteria."""
pass
@abstractmethod
async def get_keyboard_focus(self) -> Dict[str, Any]:
"""Get the currently focused UI element."""
pass
class BaseAutomationHandler(ABC):
"""Abstract base class for OS-specific automation handlers.

View File

@@ -562,85 +562,6 @@ class MacOSAccessibilityHandler(BaseAccessibilityHandler):
except Exception as e:
return {"success": False, "error": str(e)}
async def get_keyboard_focus(self) -> Dict[str, Any]:
"""Get the coordinates of the currently focused UI element.
Returns:
A dictionary with success status and coordinates if found.
"""
try:
# Create system-wide accessibility object
system = AXUIElementCreateSystemWide()
# Get focused element directly from system-wide element
focused_element = self.get_ax_attribute(system, kAXFocusedUIElementAttribute)
if not focused_element:
return {"success": False, "error": "Could not get focused UI element"}
# Get position of focused element
position = self.get_ax_attribute(focused_element, kAXPositionAttribute)
if not position:
return {"success": False, "error": "Could not get position of focused element"}
# Get size of focused element
size = self.get_ax_attribute(focused_element, kAXSizeAttribute)
if not size:
return {"success": False, "error": "Could not get size of focused element"}
# Convert position to point
position_point = element_value(position, kAXValueCGPointType)
if not position_point:
return {"success": False, "error": "Could not convert position to point"}
# Convert size to CGSize
size_value = element_value(size, kAXValueCGSizeType)
if not size_value:
return {"success": False, "error": "Could not convert size to CGSize"}
# Calculate center point of the element
center_x = position_point.x + (size_value.width / 2)
center_y = position_point.y + (size_value.height / 2)
# Get additional information about the focused element
role = self.get_ax_attribute(focused_element, kAXRoleAttribute)
title = self.get_ax_attribute(focused_element, kAXTitleAttribute)
value = self.get_ax_attribute(focused_element, kAXValueAttribute)
# Check if there's selected text (as mentioned in the blog post)
selected_text = self.get_ax_attribute(focused_element, kAXSelectedTextAttribute)
# Get selected text range if available
selected_range = None
selected_range_value = self.get_ax_attribute(focused_element, kAXSelectedTextRangeAttribute)
if selected_range_value:
selected_range = element_value(selected_range_value, kAXValueCFRangeType)
result = {
"success": True,
"position": {"x": position_point.x, "y": position_point.y},
"size": {"width": size_value.width, "height": size_value.height},
"center": {"x": center_x, "y": center_y},
"role": role,
"title": title,
"value": value
}
# Add selected text information if available
if selected_text:
result["selected_text"] = selected_text
if selected_range:
result["selected_range"] = {
"location": selected_range.location,
"length": selected_range.length
}
return result
except Exception as e:
return {"success": False, "error": str(e)}
class MacOSAutomationHandler(BaseAutomationHandler):
# Mouse Actions

View File

@@ -54,7 +54,6 @@ async def websocket_endpoint(websocket: WebSocket):
# Accessibility commands
"get_accessibility_tree": manager.accessibility_handler.get_accessibility_tree,
"find_element": manager.accessibility_handler.find_element,
"get_keyboard_focus": manager.accessibility_handler.get_keyboard_focus,
# Automation commands
"screenshot": manager.automation_handler.screenshot,
"left_click": manager.automation_handler.left_click,

View File

@@ -174,11 +174,6 @@ class BaseComputerInterface(ABC):
"""Get the accessibility tree of the current screen."""
pass
@abstractmethod
async def get_keyboard_focus(self) -> Dict:
"""Get the currently focused UI element."""
pass
@abstractmethod
async def to_screen_coordinates(self, x: float, y: float) -> tuple[float, float]:
"""Convert screenshot coordinates to screen coordinates.

View File

@@ -533,13 +533,6 @@ class MacOSComputerInterface(BaseComputerInterface):
raise RuntimeError(result.get("error", "Failed to get accessibility tree"))
return result
async def get_keyboard_focus(self) -> Dict[str, Any]:
"""Get the currently focused UI element."""
result = await self._send_command("get_keyboard_focus")
if not result.get("success", False):
raise RuntimeError(result.get("error", "Failed to get keyboard focus"))
return result
async def get_active_window_bounds(self) -> Dict[str, int]:
"""Get the bounds of the currently active window."""
result = await self._send_command("get_active_window_bounds")