user1350338
user1350338

Reputation: 97

The way to detect the current mouse cursor type from bash or python

I know that I can get the current location of the mouse cursor by executing "xdotool getmouselocation".

I would like to detect the current mouse cursor type such as pointer, beam, or hand cursor from bash terminal or python code. Would this be possible?

Thank you. June

Upvotes: 5

Views: 4472

Answers (2)

57ar7up
57ar7up

Reputation: 442

On MS Windows:

import win32gui    
win32gui.GetCursorInfo()

Will return something like

(1, 65539, (1920, 1080))

2nd number is ID of cursor type

On Windows 10 I get:

  • 65539 - normal

  • 65567 - pointer

  • 65541 - insert

Upvotes: 9

Nelson
Nelson

Reputation: 952

You can use xdotool to continuously click where the link would be until the program notices the window title changes. When the window title changes, that means the link has been clicked, and the new page is loading.

Clicking function:

ff_window=$(xdotool search --all --onlyvisible --pid "$(pgrep firefox)" --name ".+")

click-at-coords() {
    title_before=$(xdotool getwindowname $ff_window)
    while true; do
        sleep 1
        title_now=$(xdotool getwindowname $ff_window)
        if [[ $title_now != $title_before]]; then
            break
        else
            xdotool windowfocus --sync "$ff_window" mousemove --sync "$1" "$2" click 1
        fi
    done
}

Assuming that you're using xdotool to click using coordinates:

# replace each x and y with the coordinates of each link
# example with 2 sets of coordinates: all_coords=("67 129" "811 364")
all_coords=("x y" "x y")

for sub in "${all_coords[@]}"; do
    coords=($sub)
    click-at-coords "${coords[@]}"
done

Upvotes: 0

Related Questions