从命令行将键盘输入发送到程序 [英] Sending keyboard input to a program from command-line

查看:140
本文介绍了从命令行将键盘输入发送到程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将键盘输入发送到程序?

How do you send keyboard input to a program?

也就是说,在Linux GUI下,有没有好的手动(可编程)方式或工具, 在Linux上正在运行的程序上模拟键盘输入的过程,以便我可以发送 从命令行(例如"Control-T")到Firefox进程,然后 'hello'\ n到Gnome-Terminal进程,而没有真正关注每个 这些过程并直接输入?

That is, under a Linux GUI, is there a good manual (programmable) way, or tool, of simulating keyboard input on a running program on Linux, so that I can send from the command-line, e.g., "Control-T" to a Firefox process and "echo 'hello'\n" to a Gnome-Terminal process without actually focusing on each of those processes and typing in directly?

推荐答案

xdotool确实有一种发送击键的方式(如果仅限于焦点窗口):

xdotool does have a way of sending keystrokes if limited to a focused window:

WID=`xdotool search "Mozilla Firefox" | head -1`
xdotool windowactivate $WID
xdotool key ctrl+l

这篇关于从命令行将键盘输入发送到程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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