从bash或python检测当前鼠标光标类型的方法

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

我知道可以通过执行"xdotool getmouselocation".

获取鼠标当前位置

我想从 bash 终端或 python 代码检测当前鼠标光标类型,例如指针、光束或手形光标。这可能吗?

谢谢。 六月

您可以使用 xdotool 连续单击 link 所在的位置,直到程序注意到 window 标题发生变化。当 window 标题发生变化时,表示 link 已被点击,新页面正在加载。

点击功能:

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 "" "" click 1
        fi
    done
}

假设您使用 xdotool 来点击坐标:

# 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
import win32gui    
win32gui.GetCursorInfo()

会 return 像

(1, 65539, (1920, 1080))

第二个数字是游标类型的ID

在 Windows 10 我得到:

  • 65539 ​​- 正常

  • 65567 - 指针

  • 65541 - 插入