|
6 | 6 |
|
7 | 7 | from e2b import Sandbox as SandboxBase, CommandHandle, CommandResult, TimeoutException, CommandExitException
|
8 | 8 |
|
| 9 | +MOUSE_BUTTONS = { |
| 10 | + "left": 1, |
| 11 | + "right": 3, |
| 12 | + "middle": 2 |
| 13 | +} |
9 | 14 |
|
10 | 15 | class _VNCServer:
|
11 | 16 | def __init__(self, desktop: "Sandbox") -> None:
|
@@ -288,6 +293,18 @@ def move_mouse(self, x: int, y: int):
|
288 | 293 | """
|
289 | 294 | self.commands.run(f"xdotool mousemove --sync {x} {y}", envs={"DISPLAY": self._display})
|
290 | 295 |
|
| 296 | + def mouse_press(self, button: Literal["left", "right", "middle"] = "left"): |
| 297 | + """ |
| 298 | + Press the mouse button. |
| 299 | + """ |
| 300 | + self.commands.run(f"xdotool mousedown {MOUSE_BUTTONS[button]}", envs={"DISPLAY": self._display}) |
| 301 | + |
| 302 | + def mouse_release(self, button: Literal["left", "right", "middle"] = "left"): |
| 303 | + """ |
| 304 | + Release the mouse button. |
| 305 | + """ |
| 306 | + self.commands.run(f"xdotool mouseup {MOUSE_BUTTONS[button]}", envs={"DISPLAY": self._display}) |
| 307 | + |
291 | 308 | def get_cursor_position(self) -> tuple[int, int]:
|
292 | 309 | """
|
293 | 310 | Get the current cursor position.
|
@@ -365,7 +382,10 @@ def drag(self, fr: tuple[int, int], to: tuple[int, int]):
|
365 | 382 | :param from: The starting position.
|
366 | 383 | :param to: The ending position.
|
367 | 384 | """
|
368 |
| - self.commands.run(f"xdotool mousemove {fr[0]} {fr[1]} && xdotool mousedown 1 && xdotool mousemove {to[0]} {to[1]} && xdotool mouseup 1", envs={"DISPLAY": self._display}) |
| 385 | + self.move_mouse(fr[0], fr[1]) |
| 386 | + self.mouse_press() |
| 387 | + self.move_mouse(to[0], to[1]) |
| 388 | + self.mouse_release() |
369 | 389 |
|
370 | 390 | def wait(self, ms: int):
|
371 | 391 | """
|
|
0 commit comments