formatting fix

This commit is contained in:
Adam
2025-12-28 21:39:09 -05:00
parent f36e335c29
commit 4fd6c9908c
5 changed files with 110 additions and 278 deletions
@@ -483,6 +483,7 @@ class Diorama:
return tx, ty
return x, y
import time
from pynput.mouse import Controller as MouseController
@@ -85,6 +85,7 @@ class LinuxAccessibilityHandler(BaseAccessibilityHandler):
try:
# Use pynput mouse controller
from pynput.mouse import Controller as MouseController
m = MouseController()
x, y = m.position
return int(x), int(y)
@@ -92,6 +93,7 @@ class LinuxAccessibilityHandler(BaseAccessibilityHandler):
logger.warning(f"Failed to get cursor position: {e}")
logger.info("Getting cursor position (simulated)")
return 0, 0
def get_screen_size(self) -> Tuple[int, int]:
"""Get the screen size.
@@ -110,6 +112,7 @@ class LinuxAccessibilityHandler(BaseAccessibilityHandler):
class LinuxAutomationHandler(BaseAutomationHandler):
"""Linux implementation of automation handler using pynput."""
keyboard = KeyboardController()
mouse = MouseController()
@@ -131,7 +134,8 @@ class LinuxAutomationHandler(BaseAutomationHandler):
if x is not None and y is not None:
self.mouse.position = (x, y)
from pynput.mouse import Button
btn = getattr(Button, button if button in ["left","right","middle"] else "left")
btn = getattr(Button, button if button in ["left", "right", "middle"] else "left")
self.mouse.press(btn)
return {"success": True}
except Exception as e:
@@ -154,7 +158,8 @@ class LinuxAutomationHandler(BaseAutomationHandler):
if x is not None and y is not None:
self.mouse.position = (x, y)
from pynput.mouse import Button
btn = getattr(Button, button if button in ["left","right","middle"] else "left")
btn = getattr(Button, button if button in ["left", "right", "middle"] else "left")
self.mouse.release(btn)
return {"success": True}
except Exception as e:
@@ -188,6 +193,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.mouse import Button
if x is not None and y is not None:
self.mouse.position = (x, y)
self.mouse.click(Button.left, 1)
@@ -207,6 +213,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.mouse import Button
if x is not None and y is not None:
self.mouse.position = (x, y)
self.mouse.click(Button.right, 1)
@@ -228,6 +235,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.mouse import Button
if x is not None and y is not None:
self.mouse.position = (x, y)
self.mouse.click(Button.left, 2)
@@ -250,9 +258,10 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.mouse import Button
if x is not None and y is not None:
self.mouse.position = (x, y)
btn = getattr(Button, button if button in ["left","right","middle"] else "left")
btn = getattr(Button, button if button in ["left", "right", "middle"] else "left")
self.mouse.click(btn, 1)
return {"success": True}
except Exception as e:
@@ -274,7 +283,8 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.mouse import Button
btn = getattr(Button, button if button in ["left","right","middle"] else "left")
btn = getattr(Button, button if button in ["left", "right", "middle"] else "left")
self.mouse.press(btn)
self.mouse.position = (x, y)
self.mouse.release(btn)
@@ -297,9 +307,10 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.mouse import Button
if not path:
return {"success": False, "error": "Path is empty"}
btn = getattr(Button, button if button in ["left","right","middle"] else "left")
btn = getattr(Button, button if button in ["left", "right", "middle"] else "left")
self.mouse.position = path[0]
for x, y in path[1:]:
self.mouse.press(btn)
@@ -321,6 +332,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.keyboard import Key
k = getattr(Key, key) if hasattr(Key, key) else (key if len(key) == 1 else None)
if k is None:
return {"success": False, "error": f"Unknown key: {key}"}
@@ -340,6 +352,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.keyboard import Key
k = getattr(Key, key) if hasattr(Key, key) else (key if len(key) == 1 else None)
if k is None:
return {"success": False, "error": f"Unknown key: {key}"}
@@ -375,6 +388,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.keyboard import Key
k = getattr(Key, key) if hasattr(Key, key) else (key if len(key) == 1 else None)
if k is None:
return {"success": False, "error": f"Unknown key: {key}"}
@@ -395,6 +409,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.keyboard import Key
seq = []
for k in keys:
kk = getattr(Key, k) if hasattr(Key, k) else (k if len(k) == 1 else None)
@@ -501,6 +516,7 @@ class LinuxAutomationHandler(BaseAutomationHandler):
"""
try:
from pynput.mouse import Controller as MouseController
m = MouseController()
x, y = m.position
return {"success": True, "position": {"x": int(x), "y": int(y)}}
@@ -219,9 +219,18 @@ class WindowsAutomationHandler(BaseAutomationHandler):
"win": KBKey.cmd,
"meta": KBKey.cmd,
"capslock": KBKey.caps_lock,
"f1": KBKey.f1, "f2": KBKey.f2, "f3": KBKey.f3, "f4": KBKey.f4,
"f5": KBKey.f5, "f6": KBKey.f6, "f7": KBKey.f7, "f8": KBKey.f8,
"f9": KBKey.f9, "f10": KBKey.f10, "f11": KBKey.f11, "f12": KBKey.f12,
"f1": KBKey.f1,
"f2": KBKey.f2,
"f3": KBKey.f3,
"f4": KBKey.f4,
"f5": KBKey.f5,
"f6": KBKey.f6,
"f7": KBKey.f7,
"f8": KBKey.f8,
"f9": KBKey.f9,
"f10": KBKey.f10,
"f11": KBKey.f11,
"f12": KBKey.f12,
}
if lk in special:
return special[lk]