[英]bash script loses focus when displaying images
我试图弄清楚如何在显示图像的同时不失去对shell脚本的关注。 用户输入可以随时输入,但是看照片似乎很重要。
为了澄清,我没有问题输出图像。 显示工作正常,动画和feh等也是如此。我需要的是shellscript在显示最后拍摄的图像的同时,仍在不确定的时间内继续处理用户输入(在此示例中为“ t”)。
我在Linux上用bash编写。
这是我正在尝试的示例:
#!/bin/bash
i=0
capture() {
cd ~/Desktop/ani
streamer -c /dev/video0 -s 800x600 -o outfile$i.jpeg
display outfile$i.jpeg &
let i++
}
while true; do
#clear
read -rsn1 input
if [ "$input" = "t" ]; then
capture
else
exit
fi
done
在实际脚本中,我可能会继续拍照,所以我想继续听用户输入。 我可以想象有几种方法可以做到这一点,但我无法弄清楚。
继续收听用户输入。 你可以喜欢
while true; do
#clear
read -p "Your input: " input
if [ "$input" == "t" ]; then
capture
fi
done
解决这个问题的一种相当丑陋的方法:安装实用程序wmctrl
(在debian / Ubuntu中, sudo apt-get install wmctrl
)。 然后,在display
命令之后,添加:
sleep 1
wmctrl -i -a "$WINDOWID"
这将休眠一秒钟(为display
命令留出一些时间来完成加载-将该值调整为您认为合适的任何值)。 然后, wmctrl
将使用变量WINDOWID
的值(希望由终端仿真器设置)作为数值( -i
)并增加窗口并为其赋予焦点( -a
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.