473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Track keyboard and mouse usage

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.

Jul 17 '06 #1
16 10885
dfaber schrieb:
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.
You could use the /dev/input/event* devices. The link I had for the docs
is unfortunately dead - I guess lubusb and its python binding might help
you, too.

Diez
Jul 17 '06 #2

DiezYou could use the /dev/input/event* devices.

On the only Linux system I have available (Mojam's CentOS-based web server),
/dev/input/* are readable only by root. That doesn't seem like it would be
very useful to tools like watch unless they were to run suid to root
(creating other problems).

As the author of watch, I'm more than happy to incorporate "drivers" from
other people into the code, however, I have very little access to Linux
these days (and none on the desktop) and no Windows access.

Skip
Jul 17 '06 #3
sk**@pobox.com schrieb:
DiezYou could use the /dev/input/event* devices.

On the only Linux system I have available (Mojam's CentOS-based web server),
/dev/input/* are readable only by root. That doesn't seem like it would be
very useful to tools like watch unless they were to run suid to root
(creating other problems).
You don't need to give it root access. A simple rule for the udev that
looks like this:

KERNEL=="event[0-9]*", NAME="input/%k", MODE="0444"
will make the devices world readable. While I haven't thought about any
security implications that might have (and am not especially
knowledgeable in such things to be honest), I'm convinced it is way less
likely to introduce any exploitable holes than suid root would.

Diez
Jul 17 '06 #4
Hi!

Look PyHook ( http://cheeseshop.python.org/pypi/pyHook/1.4 )

Oooohhhhh!!! Sorry! It's for Windows...
--
MCI


Jul 17 '06 #5
So, how would I access /dev/input/ devices?
Can I just 'cat' them or read in those files?
Diez B. Roggisch wrote:
sk**@pobox.com schrieb:
DiezYou could use the /dev/input/event* devices.

On the only Linux system I have available (Mojam's CentOS-based web server),
/dev/input/* are readable only by root. That doesn't seem like it would be
very useful to tools like watch unless they were to run suid to root
(creating other problems).

You don't need to give it root access. A simple rule for the udev that
looks like this:

KERNEL=="event[0-9]*", NAME="input/%k", MODE="0444"
will make the devices world readable. While I haven't thought about any
security implications that might have (and am not especially
knowledgeable in such things to be honest), I'm convinced it is way less
likely to introduce any exploitable holes than suid root would.

Diez
Jul 17 '06 #6
So, how would I access /dev/input/ devices?
Can I just 'cat' them or read in those files?
Diez B. Roggisch wrote:
sk**@pobox.com schrieb:
DiezYou could use the /dev/input/event* devices.

On the only Linux system I have available (Mojam's CentOS-based web server),
/dev/input/* are readable only by root. That doesn't seem like it would be
very useful to tools like watch unless they were to run suid to root
(creating other problems).

You don't need to give it root access. A simple rule for the udev that
looks like this:

KERNEL=="event[0-9]*", NAME="input/%k", MODE="0444"
will make the devices world readable. While I haven't thought about any
security implications that might have (and am not especially
knowledgeable in such things to be honest), I'm convinced it is way less
likely to introduce any exploitable holes than suid root would.

Diez
Jul 17 '06 #7
dfaber schrieb:
So, how would I access /dev/input/ devices?
Can I just 'cat' them or read in those files?
Yes, just read them. Which is what cat does, btw.

If you cat your keyboard, you should see garbage appearing in the
terminal when you type any key. Same is true for the mouse.

Diez
Jul 17 '06 #8
MCILook PyHook ( http://cheeseshop.python.org/pypi/pyHook/1.4 )

MCIOooohhhhh!!! Sorry! It's for Windows...

That's okay (well, for me anyway). Watch runs on Windows. Perhaps someone
with Windows would like to plug pyHook into watch?

Skip
Jul 18 '06 #9
Is there no clean method of accessing the keyboard device or the mouse
on linux?
It seems that looking at /proc/interrupts might prove to be useful for
keyboard monitoring. What about checking if the left mouse button is
clicked or finding the position of the cursor on the screen?

Jul 18 '06 #10
That IS brain-crushingly complicated. However, thanks for the insight.
I really appreciate it.
Dennis Lee Bieber wrote:
On 17 Jul 2006 21:00:09 -0700, "dfaber" <de*******@gmail.comdeclaimed
the following in comp.lang.python:
Is there no clean method of accessing the keyboard device or the mouse
on linux?
It seems that looking at /proc/interrupts might prove to be useful for
keyboard monitoring. What about checking if the left mouse button is
clicked or finding the position of the cursor on the screen?

For a GUI application, it probably depends upon the interface
supplied by that GUI system... So far as I know, all Linux variants are
using an X-Window clone as the bottom protocol.

Problem: X-Window supports remote displays; you'd need a means of
specifying which display to track (unless you've opened a GUI
application and that application is asking for positions -- but it may
not be able to track outside the application window... Sorry to be so
vague -- I last coded an X interface back in 1990, using xt/DECWindows
calls; didn't even have a GUI designer available*)

I don't think anyone has ported raw X-protocol access to Python.

All those "monitoring" operations you are asking for are "events" to
a windowing environment, and applications have to "register" for the
events they are interested in seeing.

* If working raw xt/DECWindows wasn't bad enough... Add GKS (is that
still around?) on top of it -- I had a DECWindows UI whose main window
was a plain drawing region, and GKS was used to handle the underlying
data. The application was both graphics intensive, and needed a display
list (in scaleable coordinates to handle window resize) for refresh
operations; it used a 32 color "data" field, and four or so single color
"overlays" -- and any one of the five could be enabled/disabled without
requiring a recomputation of the drawing. This mess was because the
DECWindows/GKS application was an emulation (at the API level) of a late
70s/early 80s RAMTEK graphics engine... The "main" application was
really something like 50 specialized programs that all "connected" to
the "graphics engine", drew some data, and exited; allowing other
programs in the suite to draw on the /same/ window -- which is why the
need for GKS; refreshes couldn't ask for the source application to
repaint the screen. {The very oldest version of the software ran on
PDP-11s, hence the modular programs, the control program would collect
user data/parameters, write a "common block file" then invoke the needed
submodule as an overlay.
--
Wulfraed Dennis Lee Bieber KD6MOG
wl*****@ix.netcom.com wu******@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com)
HTTP://www.bestiaria.com/
Jul 18 '06 #11

DennisProblem: X-Window supports remote displays; you'd need a means
Dennisof specifying which display to track (unless you've opened a GUI
Dennisapplication and that application is asking for positions ...

Watch does this via server mode (sort of). You run watch on both your local
and remote machines. The remote machine forwards information about mouse
movement to the local machine.

DennisI don't think anyone has ported raw X-protocol access to Python.

There is a (defunct) Xlib wrapper for Python. Nowadays you could probably
redo just the parts you need pretty easily with ctypes.

Dennis* If working raw xt/DECWindows wasn't bad enough... Add GKS
Dennis(is that still around?) on top of it -- I had a DECWindows UI
Denniswhose [... many magical reminiscences elided ;-) ...]

I believe OpenGL pretty much killed the market for stuff like GKS. X
servers have enough features and video boards have enough performance that
for all but the most demanding graphics applications there's no desired to
write bits using something other than OpenGL and no need to expose the raw
framebuffer at the application program level.

Skip

Jul 18 '06 #12
Diez B. Roggisch wrote:
will make the devices world readable. While I haven't thought about any
security implications that might have (and am not especially
knowledgeable in such things to be honest), I'm convinced it is way less
likely to introduce any exploitable holes than suid root would.
Depending on what kind of info these devices produce, couldn't they be
used to spy on someone typing in a password? (I can't check, I'm on
FreeBSD.)
Jul 18 '06 #13
Lars wrote:
Diez B. Roggisch wrote:
>will make the devices world readable. While I haven't thought about any
security implications that might have (and am not especially
knowledgeable in such things to be honest), I'm convinced it is way less
likely to introduce any exploitable holes than suid root would.

Depending on what kind of info these devices produce, couldn't they be
used to spy on someone typing in a password? (I can't check, I'm on
FreeBSD.)
I guess so. Good point.

Diez
Jul 19 '06 #14
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...g.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.
Jul 21 '06 #15
Hi Francois,
Thank you for providing me the evdev link! That was exactly what I was
looking for. Instead of sudo'ing the script, I changed /dev/input/
directory to be world readable.
After that, I had to change the way a file was accessed in evdev.py to:
Line No: 91 #self.fd = os.open(filename, os.O_RDWR |
os.O_NONBLOCK)
self.fd = os.open(filename, os.O_RDONLY | os.O_NONBLOCK)

Runs great.

Thanks again.

fr**************@gmail.com wrote:
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...g.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.
Jul 23 '06 #16
Dennis Lee Bieber wrote:
On 17 Jul 2006 21:00:09 -0700, "dfaber" <de*******@gmail.comdeclaimed
the following in comp.lang.python:
Is there no clean method of accessing the keyboard device or the mouse
on linux?
It seems that looking at /proc/interrupts might prove to be useful for
keyboard monitoring. What about checking if the left mouse button is
clicked or finding the position of the cursor on the screen?
....
>
I don't think anyone has ported raw X-protocol access to Python.
Actually someone did. http://python-xlib.sourceforge.net/ It's old
but it works fine. Speaks X protocol in pure python.

HTH,
~Simon

Jul 24 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael J Whitmore | last post by:
Greetings, I have a very simple question. How do you simulate a user input to turn off a screen saver in Windows (either a mouse movement, mouse click, or keyboard input)? I promise I searched...
8
by: Nolan Martin | last post by:
Is it just me or are there no good librarys out there to access the keyboard or mouse? I have been looking around for a while now and can only find ones that are bundled with a bunch of other...
0
by: George Hartas | last post by:
I am using Visual C# .NET 2003 to make a ComboBox accept both mouse and keyboard selection. For mouse selection code, I double-clicked ComboBox to get the default "comboBox1_SelectedIndexChanged"...
9
by: Will Pittenger | last post by:
If I were writing a C++ program, I would write a mouse hook. Does C# and ..NET 1.1 have anything equivalent. If not, I suppose I will need to use the Win32 API. ---------- Will Pittenger...
0
by: Gamey | last post by:
I have an application that NEEDS (don't ask) to handle additional mouse and keyboard processing during DoDragDrop. Normally, DoDragDrop kindly squashes all keyboard and mouse events. Alternate,...
1
by: =?Utf-8?B?aG9tYW50Y3c=?= | last post by:
-windows xp -dell dimension 9150 The computer starts normally, loads up the blue login screen. I can move the cursor around the screen and type on keyboard. Then after roughly 3 seconds...
2
by: Doug | last post by:
Hi I am trying to find a way to make the mouse cursor move to the keyboard cursor position in an application. For example, I use an application called Enterprise Guide, and I control this...
2
by: Steven | last post by:
Hello, I want to raise the ValueChanged event ONLY when i move the track bar manually, but not the value changed, how to do in the event below? thank you Private Sub TrackBar1_ValueChanged(ByVal...
13
by: andypb123 | last post by:
Hello, The onchange event fires in IE6 in a SELECT element when scrolling through the list with the up and down arrows on the keyboard. In Firefox it only fires after you hit the enter key, which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.