A function callback every time a key is pressed (regardless of which window has focus)?

旧城冷巷雨未停 提交于 2019-11-28 01:15:09

问题


I want to write a programme (in python) on Linux (Ubuntu Linux 9.10) that will keep track of how many key presses per second/minute I make. This includes normal letter keys, and control/shift/space/etc.

Is there some way to hook into X so that I can say "when a key is pressed call this function?". Since I want to have this running in the background while I work normally, this function call will have to be able to be aware of all key presses for all programmes. I suppose it's a bit like a keylogger.

This is only a personal thing, so I don't care about making it work on Windows/OSX, and I don't care about when people have fancy remote X sessions etc.


回答1:


Take a look at what others have done already. You can take a look on how this pykeylogger code handles Linux in its backend, and see if that works for you.




回答2:


I'd recommend that you look at the StackOverflow question: Is there a cross-platform python low-level API to capture or generate keyboard events?

You could also look at the Simple Python Keylogger.

While not written in Python, you could also look at the LKL Linux KeyLogger. WEB-NES-BAY has instructions for using the LKL Linux KeyLogger.



来源:https://stackoverflow.com/questions/1901850/a-function-callback-every-time-a-key-is-pressed-regardless-of-which-window-has

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!