Get the current cursor position. :return: A tuple with the x and y coordinates :raises RuntimeError: If the cursor position cannot be determined
(self)
| 415 | self.commands.run(f"xdotool mouseup {MOUSE_BUTTONS[button]}") |
| 416 | |
| 417 | def get_cursor_position(self) -> tuple[int, int]: |
| 418 | """ |
| 419 | Get the current cursor position. |
| 420 | |
| 421 | :return: A tuple with the x and y coordinates |
| 422 | :raises RuntimeError: If the cursor position cannot be determined |
| 423 | """ |
| 424 | result = self.commands.run("xdotool getmouselocation") |
| 425 | |
| 426 | groups = re_search(r"x:(\d+)\s+y:(\d+)", result.stdout) |
| 427 | if not groups: |
| 428 | raise RuntimeError( |
| 429 | f"Failed to parse cursor position from output: {result.stdout}" |
| 430 | ) |
| 431 | |
| 432 | x, y = groups.group(1), groups.group(2) |
| 433 | if not x or not y: |
| 434 | raise RuntimeError(f"Invalid cursor position values: x={x}, y={y}") |
| 435 | |
| 436 | return int(x), int(y) |
| 437 | |
| 438 | def get_screen_size(self) -> tuple[int, int]: |
| 439 | """ |
no outgoing calls