如何让我的c ++程序自己“按键”?

时间:2022-10-15 07:27:12

Im writing a little C++ progam but got to a point from which on i could not go on: I want my program to control an external program using a certain combination of keys. Yes, this sounds like a horribly unclean workaround, but thats what i want to do ;)

我正在编写一个小小的C ++程序,但得到了一个我无法继续的点:我希望我的程序使用某些键组合来控制外部程序。是的,这听起来像是一个非常不干净的解决方法,但这就是我想要做的;)

To be more specific: I want my little C++ program to control the already running program elinks (a text based internet browser) by pressing the "esc" then "v" and then "h" -keys (this is used to toggle between html and plain text output in elinks).

更具体一点:我希望我的小C ++程序通过按“esc”然后“v”然后“h”键来控制已经运行的程序elinks(基于文本的互联网浏览器)(这用于在html之间切换)和elink中的纯文本输出)。

But unfortunately, I do not know how to get a C++ program to type a certain combination of keys (...if this is possible at all). I already tried the search function but wasnt able to find a solution. It would be very kind of you, if someone could give me a hint on what to do here.

但不幸的是,我不知道如何让C ++程序键入某些键组合(......如果这是可能的话)。我已经尝试过搜索功能,但无法找到解决方案。如果有人能给我一个关于这里做什么的暗示,那将是非常友好的。

Thanks, Spoekenkieker

P.S.: Im running Linux

P.S。:我正在运行Linux

1 个解决方案

#1


0  

If you have control over how to start the elinks browser, you can start it under the GNU screen terminal multiplexer and use its stuff command to send key inputs:

如果您可以控制如何启动elinks浏览器,则可以在GNU屏幕终端多路复用器下启动它并使用其stuff命令发送键输入:

This way you're not required to learn the complications of X Windows programming.

这样您就不需要了解X Windows编程的复杂性。

#1


0  

If you have control over how to start the elinks browser, you can start it under the GNU screen terminal multiplexer and use its stuff command to send key inputs:

如果您可以控制如何启动elinks浏览器,则可以在GNU屏幕终端多路复用器下启动它并使用其stuff命令发送键输入:

This way you're not required to learn the complications of X Windows programming.

这样您就不需要了解X Windows编程的复杂性。