BASH xdool鼠标单击,重复并停止

BASH xdool鼠标单击,重复并停止,bash,xdotool,Bash,Xdotool,我正在尝试使用xdoool将一个简单的无限点击脚本与另一个脚本集成起来,以检测键盘输入;当按下某个键但不确定如何匹配时,结束正在运行的单击脚本 该脚本在xdool确定的屏幕光标点XXX,YYY无限重复地运行 #!/bin/bash while true [ 1 ]; do xdotool mousemove XXX YYY click 1 & sleep 1.5 done 下一步,我希望使用如下内容: #!/bin/bash if [ -t 0 ]; then stty -e

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

该脚本在xdool确定的屏幕光标点XXX,YYY无限重复地运行

 #!/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混乱和manbash没有帮助,所以任何能提供帮助的人都会很感激。感谢改进(和评论)脚本:

#!/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 runs from a terminal.
test -t 0 || exit 1

# When killed, run stty sane.
trap 'stty sane; exit' SIGINT SIGKILL SIGTERM

# When exits, kill this script and it's child processes (the loop).
trap 'kill 0' EXIT

# Do not show ^Key when press Ctrl+Key.
stty -echo -icanon -icrnl time 0 min 0

# While the pears become pears...
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