Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...