linux - Linux shell script on background, loop exit reading keyboard buffer
问题描述
On one laptop with x-ubuntu 18.04 I have a shell script (.sh) which automates a series of clicks on a webapp (via xdotool). Everything works fine but I need to be able to stop the script at the push of a button (while the focus is on the browser due to the clicks). For now I have buffered by clicking the script on the terminal window every k (read from terminal) iterations and giving a sleep of 5 seconds, so that I can press ctrl + c. This solution, however, as well as being not very elegant, forces me to always keep the terminal and browser in the same position and a 5 seconds "lost" every k iterations. I attach summary script, I really tried everything but I can't figure out with it, some time ago I made the same script in C++ (but I sadly was under windows and I can't use c++ on this laptop) going to read the keyboard buffer... ps: I can't use various autoclicker because the script in addition to clicking also does other stuff (it launches programs, updates databases, etc.)
#!/bin/sh
p_p()
{ # brings the terminal window to the front
xdotool mousemove 300 0
sleep 0.5 # top-panel up
xdotool click 1
}
i=1
echo "every how many iterations do you want the possibility to interrupt?"
read k
until [ $i -gt 100000000000 ]
do
for X in $(seq 3)
do
xdotool mousemove 974 431
xdotool click 1
sleep 0.1
done
#here there is a function for other stuff
remainder=$(( i % k ))
if [ "$remainder" -eq 0 ]; then
p_p
echo "press ctrl + c for interrupt"
sleep 5
else
sleep 0.5
fi
i=$(( i+1 ))
echo "$i"
done
echo "security limit reached"
解决方案
推荐阅读
- wordpress - 在类别末尾出售的产品
- spring-boot - 我们可以回滚 kafka 消息吗
- java - Exoplayer 无法正确播放大型本地视频
- python - 根据唯一的 col 值合并两个数据帧
- html - 链接引导程序和 JS 文件时 CSS 未链接到 Html
- php - array_uintersect 与子数组不相交第一项
- c++ - 在套接字编程中强制转换 sockaddr 违反 MISRA C++ 2008 规则 5-2-7
- react-native - 当我调用 api 时,redux 不会等待 api 调用的响应,甚至在得到响应之前就调用失败案例
- amazon-web-services - 将数据从 AWS Elasticsearch 移动到 S3
- for-loop - BATCH FOR-loop,但从特定文件开始