4

我知道我可以通过执行“xdotool getmouselocation”来获取鼠标光标的当前位置。

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

谢谢你。六月

4

2 回答 2

2
import win32gui    
win32gui.GetCursorInfo()

会返回类似的东西

(1, 65539 , (1920, 1080))

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

在 Windows 10 上,我得到:

  • 65539 ​​- 正常

  • 65567 - 指针

  • 65541 - 插入

于 2019-07-28T23:30:20.740 回答
0

您可以使用 xdotool 连续单击链接所在的位置,直到程序注意到窗口标题更改为止。当窗口标题发生变化时,这意味着该链接已被单击,并且正在加载新页面。

点击功能:

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
}

假设您使用 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
于 2017-07-14T15:26:31.870 回答