我正在尝试使用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并没有帮助,所以任何可以提供帮助的人都会受到赞赏。致谢
答案 0 :(得分:4)
改进(和评论)的脚本:
#!/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