Skip to content

Commit eda04a0

Browse files
Merge pull request #233 from askui/feat/mouse_move_speed
feat: make `duration` a parameter of `mouse_movement` to enable fast mouse movement
2 parents 61e42df + a3dc0ac commit eda04a0

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/askui/tools/agent_os.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,14 @@ def screenshot(self, report: bool = True) -> Image.Image:
261261
raise NotImplementedError
262262

263263
@abstractmethod
264-
def mouse_move(self, x: int, y: int) -> None:
264+
def mouse_move(self, x: int, y: int, duration: int = 500) -> None:
265265
"""
266266
Moves the mouse cursor to specified screen coordinates.
267267
268268
Args:
269269
x (int): The horizontal coordinate (in pixels) to move to.
270270
y (int): The vertical coordinate (in pixels) to move to.
271+
duration (int): The duration (in ms) the movement should take.
271272
"""
272273
raise NotImplementedError
273274

src/askui/tools/askui/askui_controller.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,25 +367,26 @@ def screenshot(self, report: bool = True) -> Image.Image:
367367

368368
@telemetry.record_call()
369369
@override
370-
def mouse_move(self, x: int, y: int) -> None:
370+
def mouse_move(self, x: int, y: int, duration: int = 500) -> None:
371371
"""
372372
Moves the mouse cursor to specified screen coordinates.
373373
374374
Args:
375375
x (int): The horizontal coordinate (in pixels) to move to.
376376
y (int): The vertical coordinate (in pixels) to move to.
377+
duration (int): The duration (in ms) the movement should take.
377378
"""
378379
self._reporter.add_message(
379380
"AgentOS",
380-
f"mouse_move({x}, {y})",
381+
f"mouse_move({x}, {y}, duration={duration})",
381382
AnnotatedImage(lambda: self.screenshot(report=False), point_list=[(x, y)]),
382383
)
383384
self._run_recorder_action(
384385
acion_class_id=controller_v1_pbs.ActionClassID_MouseMove,
385386
action_parameters=controller_v1_pbs.ActionParameters(
386387
mouseMove=controller_v1_pbs.ActionParameters_MouseMove(
387388
position=controller_v1_pbs.Coordinate2(x=x, y=y),
388-
milliseconds=500,
389+
milliseconds=duration,
389390
)
390391
),
391392
)

src/askui/tools/computer_agent_os_facade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def screenshot(self, report: bool = True) -> Image.Image:
5757
)
5858
return scale_image_to_fit(screenshot, self._target_resolution)
5959

60-
def mouse_move(self, x: int, y: int) -> None:
60+
def mouse_move(self, x: int, y: int, duration: int = 500) -> None:
6161
scaled_x, scaled_y = self._scale_coordinates_back(x, y)
62-
self._agent_os.mouse_move(scaled_x, scaled_y)
62+
self._agent_os.mouse_move(scaled_x, scaled_y, duration)
6363

6464
def get_mouse_position(self) -> Coordinate:
6565
mouse_position = self._agent_os.get_mouse_position()

src/askui/tools/playwright/agent_os.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,14 @@ def screenshot(self, report: bool = True) -> Image.Image:
179179
return Image.open(io.BytesIO(screenshot_bytes))
180180

181181
@override
182-
def mouse_move(self, x: int, y: int) -> None:
182+
def mouse_move(self, x: int, y: int, _duration: int = 500) -> None:
183183
"""
184184
Moves the mouse cursor to specified coordinates on the page.
185185
186186
Args:
187187
x (int): The horizontal coordinate (in pixels) to move to.
188188
y (int): The vertical coordinate (in pixels) to move to.
189+
_duration (int): Unused parameter as it is not applicable here.
189190
"""
190191
if not self._page:
191192
error_msg = "No active page. Call connect() first."

0 commit comments

Comments
 (0)