Skip to content

Commit 0e99b58

Browse files
PauliusPaulius
authored andcommitted
Make mouse movements visible
1 parent b6bdefe commit 0e99b58

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/generalagents/macos/computer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import tempfile
33
import time
44
from fractions import Fraction
5+
from pytweening import easeInOutQuad
56

67
import pyautogui
78
from PIL import Image
@@ -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)