我想编写一个应用程序,它将像一个守护进程一样工作,并且在一些全局击键上将一些文本粘贴到当前活动的应用程序(文本编辑器、浏览器、jabber 客户端)我想我需要使用一些低级别的 xserver api。我如何用 Python 或 C++ 做到这一点?
问问题
385 次
2 回答
1
可能你想破解xmon ...
AFAIK 没有简单的方法来挂钩 X 协议。您将需要执行“深度数据包检查”,这在应用程序事件循环中相当容易,但并非如您所愿,“像守护程序”或“全局击键[s]”。
所以,我知道这真的是蛮力和无知的,但我认为你必须通过在非标准端口上启动它或发布环境变量来包装 X 服务器,就像你使用 SSH 隧道之类的东西来转发一样X 服务器连接。
有一个名为 Xmon 的 X 协议监视器,它的源可用。这可能是一个很好的起点。
于 2009-09-26T08:03:14.120 回答
0
我认为您可以使用xmacro中的 xmacroplay 实用程序在 X windows 下执行此操作。要么直接使用它——使用 subprocess 模块将命令发送到标准输入,或者阅读源代码并了解它是如何做到的!我不认为它有 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做类似的事情。
于 2009-09-26T09:16:02.827 回答