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

痞子三分冷 提交于 2021-02-09 08:17:27

问题


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


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/45097307/the-way-to-detect-the-current-mouse-cursor-type-from-bash-or-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!