BASH XDOTool鼠标单击,重复和停止 [英] BASH XDOTool Mouse click, repeat and stop

查看:182
本文介绍了BASH XDOTool鼠标单击,重复和停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to integrate a simple infinite click script using XDOToool with another piece of script to detect keyboard input; to end the running clicking script when a key is pressed but unsure how to match them up.

此脚本无限次地运行,反复单击XDOTool确定的屏幕光标点XXX,YYY

This script runs infinitely repetitively clicking at screen cursor point XXX, YYY determined by XDOTool

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

下一步,我希望使用类似的东西:

Next I wish to use something like:

#!/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

我不明白我该如何服用:

I don't understand how I take the:

 xdotool mousemove XXX YYY click 1 &
 sleep 1.5

在上面的脚本中放置它的位置,BASH的混乱和MAN BASH并没有帮助,因此任何可以提供帮助的人都会感激.谢谢

And where to put it in the script above, BASH confusion and MAN BASH doesn't help so anyone who could assist would be appreciated. THANKS

推荐答案

改进(并带有注释)的脚本:

Improved (and commented) script:

#!/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

这篇关于BASH XDOTool鼠标单击,重复和停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆