3

我正在尝试将使用 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 没有帮助,所以任何可以提供帮助的人都会受到赞赏。谢谢

4

1 回答 1

6

改进(和评论)脚本:

#!/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
于 2015-04-19T13:03:14.303 回答