在一些全局击键中,我如何使用Python或C ++将一些文本粘贴到Linux中的当前活动应用程序中

时间:2009-09-26 07:18:02

标签: c++ python linux xserver

我想编写应用程序,它将像守护进程一样工作,并在一些全局按键上粘贴一些文本到当前活动应用程序(文本编辑器,浏览器,jabber客户端)我想我将需要使用一些低级别的xserver api。我如何用Python或C ++做到这一点?

2 个答案:

答案 0 :(得分:1)

可能你想破解xmon ......


AFAIK没有简单的方法来挂钩X协议。您将需要进行“深度数据包检查”,这在应用程序事件循环中相当容易,但不是那么容易,就像您想要的那样,“像守护进程”,或“全局击键[s]”。

所以,我知道这真的是暴力和无知,但我认为你必须通过在非标准端口上启动或发布环境变量来包装X服务器,就像你使用像SSH这样的东西隧道转发X服务器连接。

有一个名为Xmon的X协议监视器,其源可用。这可能是一个很好的起点。

答案 1 :(得分:0)

您可以使用xmacroplay utility from xmacro在我认为的X窗口下执行此操作。直接使用它 - 使用子进程模块将命令发送到标准输入,或者阅读源代码并了解它是如何做到的!我不认为它有python绑定。

来自xmacroplay网站

xmacroplay:
Reads lines from the standard input. It can understand the following lines:

Delay [sec]     - delays the program with [sec] secundums
ButtonPress [n] - sends a ButtonPress event with button [n]
          this emulates the pressing of the mouse button [n]
ButtonRelease [n]   - sends a ButtonRelease event with button [n]
          this emulates the releasing of the mouse button [n]
... snip lots more ...

这可能是您感兴趣的命令

String [max. 1024 long string]
        - Sends the string as single characters converted to
          KeyPress and KeyRelease events based on a
          character table in chartbl.h (currently only
          Latin1 is used...)

还有Xnee做了类似的事情。

相关问题