bash - 我如何在 bash 中获取当前的鼠标坐标?

标签 bash shell unix mouse

我需要在 bash 中获取当前的鼠标坐标,而 xdotool 似乎对我不起作用。我该怎么做?

最佳答案

为了避免所有 sed/awk/cut 的东西,你可以使用

xdotool getmouselocation --shell

特别是,

eval $(xdotool getmouselocation --shell)

会将位置放入 shell 变量 XYSCREEN。之后,

echo $X $Y

将为以后的 xdotool mousemove 或任何其他用途提供一个片段。


我的连续点击几个位置的额外是一个文件 positions.txt(由几个 eval/echo 运行给出):

123 13
423 243
232 989

使用它的代码是:

while read line; do
     X=`echo $line| cut -c1-3`; 
     Y=`echo $line| cut -c4-7`;
     xdotool mousemove --sync $((  0.5 + $X )) $(( 0.5 + $Y ));
     xdotool click 1
done < positions.txt

如果不需要缩放像素(不像我的情况),它可能很简单

while read line; do
     xdotool mousemove --sync $line;
     xdotool click 1
done < positions.txt

关于bash - 我如何在 bash 中获取当前的鼠标坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8480073/

相关文章:

linux - Bash - 获取两个字符之间的字符串

bash - 从终端/bash 获取 Macbook 屏幕尺寸

linux - 将除五个最新文件之外的所有文件移至新目录

unix - 为什么 file2 在 'cat file1>file2>file3' 之后为空?

bash - 我怎样才能正确地将多个 bash 脚本源到彼此?

linux - 如何在目录和子目录的文件中递归搜索模式并生成sha1sum?

bash - 如果不存在,bash会创建许多目录

python - R: system() 不能使用 .bashrc 中定义的 bash 函数

python - postgres 找到所有者为 'abc' 的所有数据库?

linux - 将命令的输出分配给变量(BASH)