Simple question from Python Newbie

Carl Banks imbosol at aerojockey.invalid
Mon Dec 15 00:43:17 EST 2003


Tim Roberts wrote:
> "Phil D." <phildog22 at yahoo.com> wrote:
>>
>>Hello Python Hackers!
>> 
>>I just started working with Python a few days ago and have a simple 
>>question that I can't seem to figure out.  I am trying to build an
>>application to monitor my mouse moving habits while I'm surfing
>>the web for a project at MIT and I can't seem to figure out how
>>to capture mouse clicks.
> 
> Actually, this is not a particularly simple question.  The issue is that it
> isn't related to Python at all: this is an operating system issue.  An
> application is expected to be interested only the events that relate
> directly to that application.  Doing so on a system wide basis is usually
> only interesting for toy apps, such as the one you want to build.
> 
> Fortunately, Windows provides a way to do that: it's called a "hook".  In
> this case, what you want is the "journal record hook" (WH_JOURNALRECORD),
> which gets all key and mouse events in the system.  This requires a
> callback, which means it needs C help.  I don't know if it is implemented
> in any of the Win32 extensions; I will have to investigate that (and hope
> someone like Mark Hammond posts the canned answer).


In Linux, you can open the mouse device file and read to your heart's
content.  (Or you can configure GPM to open a mouse repeater device,
and read from that.)  It'll probably need some ioctl calls, but
nothing Python can't do wihtout help from C.

Figuring out how to read from the device and process the mouse
protocol is left as an exercise.


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon




More information about the Python-list mailing list