如何将键盘输入发送到程序?
也就是说,在Linux GUI下,是否有一个好的手动(可编程)方式或工具, 在Linux上运行的程序上模拟键盘输入,以便我可以发送 从命令行,例如“Control-T”到Firefox进程和“echo” '你好'\ n“到一个Gnome-Terminal进程而没有实际关注每个进程 这些流程并直接输入?
答案 0 :(得分:15)
xdotool
确实有一种发送击键的方法:
WID=`xdotool search "Mozilla Firefox" | head -1`
xdotool windowactivate $WID
xdotool key ctrl+l
答案 1 :(得分:2)
我在xdotool
附近构建了一个Ruby DSL,以简化窗口的聚焦和键盘输入的模拟。这是一个例子,重复原始请求:
Mani.new(window_manager: :xmonad) do
window :hello, launch: 'urxvt' do
run 'echo "hello\n"'
end
window :firefox, launch: 'firefox', delay: 1.5 do
type '{{ctrl+t}}'
end
end
答案 2 :(得分:2)
这是一个古老的主题,但是仍然可能正在寻找这个,有人在这里提到解决方案,在使用xdotool时必须激活窗口。但是,您可以指定窗口甚至使用xdotool来查找它。这是我试图完成的示例,根据需要进行更改。
xdotool key --window $(xdotool search --name "Spotify (Premium |Free )?- Linux Preview" | head -n1) ctrl+KP_Down
答案 3 :(得分:1)
我发现这两个程序xmacro和xremote你可能会看一看,但似乎没有很好的记录。
我还发现这个实用程序xvkbd
回答了这个题为问题的问题:Sending keycode to Xorg + wine with bash script。