BlueM / cliclick

macOS CLI tool for emulating mouse and keyboard events
https://www.bluem.net
Other
1.59k stars 116 forks source link

Relative coordinates don't work when trying to access point on external display #175

Closed ksylvan closed 9 months ago

ksylvan commented 9 months ago

I have a LG HDR WQHD external display arranged to the left of my my Macbook built-in-display.

Like this:

Screenshot 2023-11-26 at 9 20 04 AM

As a result, (0,0) is the top left of the built-in display, and the entire desktop has these dimensions:

osascript -e 'tell app "Finder" to get bounds of window of desktop'
-3440, 0, 1470, 1440

Therefore, when I try to access a UI element at -1428,244 (on my external display), it does not work as expected, because cliclick interprets the "-1428" to be a relative x coordinate.

My workaround was to first move the mouse to (0,0) before performing the cliclick action, like this:

on moveMouse(x, y)
    -- x and y can be negative, depending on the arrangement of external displays
    -- in that case, cliclick will be confused by its relative position feature.
    if x < 0 or y < 0 then
        do shell script cliclick & " m:0,0"
    end if
    do shell script cliclick & " m:" & x & "," & y
end moveMouse

on clickMouse(x, y)
    -- x and y can be negative, depending on the arrangement of external displays
    -- in that case, cliclick will be confused by its relative position feature.
    if x < 0 or y < 0 then
        do shell script cliclick & " m:0,0"
    end if
    do shell script cliclick & " c:" & x & "," & y
end clickMouse

It would be cleaner if cliclick had an absolute positioning mode, where if I pass it coordinates like -1428,244 it does the action at that absolute position.

BlueM commented 9 months ago

From the output cliclick prints when invoked with -h switch:

If you need to specify absolute negative values in case you have a setup with a second display arranged to the left of your main display, prefix the number with “=”, for instance “c:100,=-200”.

ksylvan commented 9 months ago

Thanks, @BlueM - I totally missed that. Brilliant.