本文共 3182 字,大约阅读时间需要 10 分钟。
linux模拟键盘按键
Automatic keyboard pressers are useful . However, it seems that there is no simple and easy to use automatic keyboard presser for if you search for “automatic keyboard presser linux”. After some digging, I find using the with some options is a good method for automatic keyboard pressing though it is not designed for this purpose.
自动键盘按下器是有用的 。 但是,如果您搜索“ 自动键盘按键”,似乎没有简单易用的自动键盘按键。 经过一番挖掘后,我发现使用和一些选项是自动按键盘的好方法,尽管它不是为此目的而设计的。
Let’s use one example here to introduce how to use xvkbd
as a automatic keyboard presser: we want to refresh the browser every 5 seconds to check a webpage for changes. If you do it manually, you press Ctrl + r
every 5 seconds. Let’s make the computer do it automatically for us while what we need to do is just to watch the screen while drinking a cup of tea.
让我们在这里使用一个示例来介绍如何将xvkbd
用作自动键盘xvkbd
器:我们希望每5秒刷新一次浏览器以检查网页是否有变化。 如果您手动执行此操作,则每5秒按Ctrl + r
。 让我们让计算机为我们自动完成它,而我们需要做的就是只是在喝杯茶的同时观看屏幕。
xvkbd
has an option -text
which can send the string to the focused window:
xvkbd
有一个选项-text
它可以将字符串发送到焦点窗口:
-text stringSend the string to the focused window (see also `-window' option). If this option is specified, xvkbd will not open its window and terminate soon after sending the string.The string can contain:\r - Return\t - Tab\b - Backspace\e - Escape\d - Delete\S - Shift (modify the next character; please note that modify with ``\S'' will be ignored in many cases. For example, ``a\Cb\ScD\CE'' will be interpreted as a, Control-b, c, Shift-D, and Control-Shift-E.)\C - Control (modify the next character)\A - Alt (modify the next character)\M - Meta (modify the next character)\[keysym] - the keysym keysym (e.g., \[Left]), which will be processed in the similar matter with other general characters\{keysym} - the keysym keysym (e.g., \{Left}), which will be processed in more primitive matter and can also be used for modofier keys such as Control_L, Meta_L, etc.; also, \{+keysym} and \{+keysym} will simulate press and release of the key, respectively \Ddigit - delay digit * 100 ms\xvalue - move mouse pointer (use "+" or "-" for relative motion)\yvalue - move mouse pointer (use "+" or "-" for relative motion)\mdigit - simulate click of the specified mouse button
With this option, we can send out Ctrl + r
by:
使用此选项,我们可以通过以下方式发送Ctrl + r
:
xvkbd -text "\Cr"
With the option of xvkbd
, we can write our own automatic key presser with a bit bash script to repeatedly invoke xvkbd
.
使用xvkbd
选项,我们可以使用一些bash脚本编写自己的自动按键,以重复调用xvkbd
。
Here comes the script that automatically refresh the browser (the active window).
这是自动刷新浏览器(活动窗口)的脚本。
while true; do xvkbd -text "\Cr"; sleep 5; done;
Execute it in a , make the browser focused and then you can watch the page “automatically” refreshed.
在执行它,使浏览器聚焦,然后您可以观看“自动”刷新的页面。
When you want to stop the “automatic keyboard presser”, just press Ctrl+c
in the shell window.
当您要停止“自动键盘按下器”时,只需在外壳程序窗口中按Ctrl+c
。
More interesting and complex key pressers can be made using the functions provided by xvkbd
(especially the \D
to delay a little while).
可以使用xvkbd
提供的功能(尤其是\D
稍有延迟)来制作更有趣,更复杂的按键。
翻译自:
linux模拟键盘按键
转载地址:http://zoowd.baihongyu.com/