Track keyboard and mouse usage

francois.schnell at gmail.com francois.schnell at gmail.com
Fri Jul 21 18:06:25 EDT 2006


Hello dfaber,

I had the same problem not long ago. I tried to use the Xlib since its
obvious the X server  has all the events but I couldn't have the mouse
events if my app was out of focus. If you have a way to do that I'm
really interested.

Anyway I found this to be a good introduction to Xlib:
http://users.actcom.co.il/~choo/lupg/tutorials/xlib-programming/xlib-programming.html#preface

Since I didn't find a way to do it I went down to the source of the
events which are provided by the evdev drivers:
http://en.wikipedia.org/wiki/Evdev

Fortunately you can use Python to access it:
http://svn.navi.cx/misc/trunk/python/evdev/

First you need to know your input devices, search the eventX in
relation to your device here:
cat /proc/bus/input/devices

Then you can do:
sudo python evdev.py /dev/input/eventX  # where X is the event number
in relation to your device (kb is usually zero)

It works well but there is two problems with this solution:
- the root access is annoying (but I'll have to try Diez suggestion)
- The X event number of the mouse can change from a PC to another one
(you need to check the PC first with that cat command and search for
your "mouse"

francois





dfaber wrote:
> Hi all,
>  I have been searching for a keyboard and mouse tracker on linux. I've
> read solutions (watch at sourceforge) which look at /proc/interrupts to
> check keyboard or mouse activity. I also read one post where "watch"
> seems to have difficulty tracking usb keyboards and mice. So, I'm out
> of ideas here.
>
> My goal are:
> 1. Check keyboard activity. I'm not interested in logging which keys
> are pressed or record them.
> 2. Monitor mouse activity. I want to know the pointer position,
> left-clicks, right-clicks, middle-mouse button usage.
>
> I know that these things can be done in a GUI environment. I am looking
> for some approach that helps me do this system-wide.
>
> Any suggestions would be welcome. Again, I am looking for trackers on
> Linux based machines.




More information about the Python-list mailing list