开发者

Intercept and send keystrokes with Python on Linux

I'm looking for a way to intercept all keyboard signals before they reach the active application. I t开发者_如何转开发hen want to interpret and map the keystrokes before sending them on to the currently active application.

A Python library would be great, but C/C++ would also suffice.


I'm assuming you are using a system with X(org). If not some stuff can be done as well as the evdev level, but that's a another story.

Two parts in your question:

  1. intercepting all key events -> XGrabKeyboard()
  2. sending key events to the active application: I'd use libfakekey, it's a bit hacky hacky (it dynamically remaps part of the current keymap to send the KeySym you want to send) but it worked for me (small tip, don't forget to gerenate both the key presses and key release events :p).

Of course in your application grabbing the keyboard, you will have to listen to the KeyEvents from X and send keys from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜