gpt4 book ai didi

BASH XDOTool 鼠标点击、重复和停止

转载 作者:行者123 更新时间:2023-11-29 09:47:22 26 4
gpt4 key购买 nike

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

此脚本无限重复点击屏幕光标点 XXX,XDOTool 确定的 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 混淆和 MAN BASH 没有帮助,所以任何可以提供帮助的人都将不胜感激。谢谢

最佳答案

改进(和注释)脚本:

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

关于BASH XDOTool 鼠标点击、重复和停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29729770/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com