Callback function every time you press a key (no matter which window has focus)?

I want to write a program (in python) on Linux (Ubuntu Linux 9.10) that will track how many keystrokes per second / minute I do. This includes regular letter keys and control / shift / space / etc.

Is there a way to connect to X so that I can say "when the key is pressed to call this function?". Since I want this to be executed in the background while running, this function call should be able to know all the keystrokes for all programs. I guess this is a bit like a keylogger.

This is only a private matter, so I don’t care that it works on Windows / OSX, and I don’t care when people get interesting X sessions, etc.

+5
python linux keypress keylogger xorg
source share
2 answers

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

+5
source share

I would advise you to take a look at the StackOverflow question: Is there a cross-platform, low-level python API for capturing or generating keyboard events?

You can also look at Simple Python Keylogger .

Not yet written in Python, you can also look at LKL Linux KeyLogger . WEB-NES-BAY has instructions for using LKL Linux KeyLogger .

+5
source share

All Articles