Skip to content

Commit e2cb2b1

Browse files
Pauliuspsarka
authored andcommitted
Make mouse movements visible
1 parent 246eb6e commit e2cb2b1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/generalagents/macos/computer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pyautogui
77
from PIL import Image
8+
from pytweening import easeInOutQuad
89

910
from generalagents.action import (
1011
Action,
@@ -24,6 +25,7 @@
2425

2526
pyautogui.FAILSAFE = True # Move mouse to corner to abort
2627
pyautogui.PAUSE = 0.001 # We are waiting manually in the code
28+
MOUSE_SETTINGS = {"duration": 0.101, "tween": easeInOutQuad} # duration <= 0.1 is treated as 0 by pyautogui
2729

2830

2931
class Computer:
@@ -62,19 +64,19 @@ def _execute_action(self, action: Action) -> None:
6264
pyautogui.write(text)
6365

6466
case ActionLeftClick(kind="left_click", coordinate=coord):
65-
pyautogui.click(*self._scaled(coord), button="left")
67+
pyautogui.click(*self._scaled(coord), button="left", **MOUSE_SETTINGS)
6668

6769
case ActionRightClick(kind="right_click", coordinate=coord):
68-
pyautogui.click(*self._scaled(coord), button="right")
70+
pyautogui.click(*self._scaled(coord), button="right", **MOUSE_SETTINGS)
6971

7072
case ActionDoubleClick(kind="double_click", coordinate=coord):
71-
pyautogui.doubleClick(*self._scaled(coord))
73+
pyautogui.doubleClick(*self._scaled(coord), **MOUSE_SETTINGS)
7274

7375
case ActionTripleClick(kind="triple_click", coordinate=coord):
74-
pyautogui.tripleClick(*self._scaled(coord))
76+
pyautogui.tripleClick(*self._scaled(coord), **MOUSE_SETTINGS)
7577

7678
case ActionMouseMove(kind="mouse_move", coordinate=coord):
77-
pyautogui.moveTo(*self._scaled(coord))
79+
pyautogui.moveTo(*self._scaled(coord), **MOUSE_SETTINGS)
7880

7981
case ActionDrag(kind="drag", drag_start=start, drag_end=end):
8082
pyautogui.moveTo(*self._scaled(start))

0 commit comments

Comments
 (0)