Simple question from Python Newbie
timr at probo.com
Mon Dec 15 05:34:34 CET 2003
"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).
>Thoughts anyone? What's the easiest way to get mouse clicks outside of a GUI?
Your terminology is a bit confusing. The entire desktop is "a GUI". What
you really want is to get mouse clicks outside of your own process.
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list