BASH XDOTool 鼠标单击、重复并停止



我正在尝试使用 XDOToool 将一个简单的无限单击脚本与另一段脚本集成以检测键盘输入;在按下某个键但不确定如何匹配它们时结束正在运行的单击脚本。

此脚本无限重复单击屏幕光标点 XXX,YYY 由 XDOTool 确定

 #!/bin/bash
 while true [ 1 ]; do
 xdotool mousemove XXX YYY click 1 &
 sleep 1.5
 done

接下来,我希望使用类似以下内容的内容:

#!/bin/bash
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 min 0; fi
count=0
keypress=''
while [ "x$keypress" = "x" ]; do
let count+=1
echo -ne $count'r'
keypress="`cat -v`"
done
if [ -t 0 ]; then stty sane; fi
echo "You pressed '$keypress' after $count loop iterations"
echo "Thanks for using this script."
exit 0

我不明白我如何采取:

 xdotool mousemove XXX YYY click 1 &
 sleep 1.5

以及将其放在上面的脚本中的位置,BASH 混乱和 MAN BASH 无济于事,因此任何可以提供帮助的人都将不胜感激。谢谢

改进(和注释)脚本:

#!/bin/bash
x_pos="0"   # Position of the mouse pointer in X.
y_pos="0"   # Position of the mouse pointer in Y.
delay="1.5" # Delay between clicks.
# Exit if not running from a terminal.
test -t 0 || exit 1
# When killed, run stty sane.
trap 'stty sane; exit' SIGINT SIGKILL SIGTERM
# On exit, kill this script and it's child processes (the loop).
trap 'kill 0' EXIT
# Do not show ^Key when pressing Ctrl+Key.
stty -echo -icanon -icrnl time 0 min 0
# Infinite loop...
while true; do
    xdotool mousemove "$x_pos" "$y_pos" click 1 &
    sleep "$delay"
done & # Note the &: We are running the loop in the background to let read to act.
# Pause until reads a character.
read -n 1
# Exit.
exit 0

相关内容

  • 没有找到相关文章

最新更新