2015-04-19 18 views
1

我正在尝试使用XDOToool与另一块脚本来检测键盘输入的简单无限点击脚本;在按下按键时结束正在运行的点击脚本,但不确定如何匹配它们。BASH XDOTool鼠标单击,重复和停止

运行此脚本无限重复点击在屏幕上的光标点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

难道我的答案的工作? – Helio

回答

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