* Get the current cursor position. * @returns A object with the x and y coordinates * @throws Error if cursor position cannot be determined
()
| 360 | * @throws Error if cursor position cannot be determined |
| 361 | */ |
| 362 | async getCursorPosition(): Promise<CursorPosition> { |
| 363 | const result = await this.commands.run('xdotool getmouselocation') |
| 364 | |
| 365 | const match = result.stdout.match(/x:(\d+)\s+y:(\d+)/) |
| 366 | if (!match) { |
| 367 | throw new Error( |
| 368 | `Failed to parse cursor position from output: ${result.stdout}` |
| 369 | ) |
| 370 | } |
| 371 | |
| 372 | const [, x, y] = match |
| 373 | if (!x || !y) { |
| 374 | throw new Error(`Invalid cursor position values: x=${x}, y=${y}`) |
| 375 | } |
| 376 | |
| 377 | return { x: parseInt(x), y: parseInt(y) } |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Get the current screen size. |