[Techtalk] Detection of mouse-clicks and/or keypresses in Python

David Sumbler david at aeolia.co.uk
Wed Jun 3 16:38:32 UTC 2015


Actually this looks as if it could be just what I was looking for.  I
actually need timing to a fraction of a second, but removing the sleep
and adding :%f to display microseconds seems to show that it would serve
my purpose pretty well.

Shame it doesn't work for mouse clicks, but I can probably manage with
key-presses.

Thanks a lot.

David



On Wed, 2015-06-03 at 09:05 -0700, Patrick Olson wrote:
> It looks like attachments aren't allowed. If anyone wants to see the code
> I'd attached, http://pastebin.ca/3017020
> 
> On Wed, June 3, 2015 8:41 am, Patrick Olson wrote:
> > I doubt the attached is exactly what you want to do, but it does print the
> > time when a key is pressed. Perhaps it will be a start towards what you're
> > trying to do. My python version is 2.7.3, but I assume 3 would be
> > backwards compatible, at least for code as simple as I've written.
> >
> > I created this by removing most of the code from a utility I'd created for
> > myself, so it's probably not the most efficient way to do it, and may
> > import some things that aren't needed. Also, the time isn't truly exact
> > since there is a "time.sleep(1)" in the loop. However, without that it
> > takes a lot of CPU cycles, at least on an older computer.
> >
> > Hope this helps!
> >
> > On Wed, June 3, 2015 3:48 am, David Sumbler wrote:
> >> I want to write a simple program in Python 3, for my own use, which will
> >> detect mouse-clicks (or possibly key-presses from the keyboard) and
> >> record the exact time of each event.
> >>
> >> In principle this should be easy enough, except that I do not know how
> >> to detect the events themselves.
> >>
> >> The only information I need to collect is the time of the event: for
> >> this particular program I am not interested in recording which button or
> >> key is pressed.
> >>
> >> I have searched on the internet, but I can't seem to find what I want.
> >> What would be the simplest way to detect these events using Python?
> >>
> >> David
> >>
> >> _______________________________________________
> >> Techtalk mailing list
> >> Techtalk at linuxchix.org
> >> http://mailman.linuxchix.org/mailman/listinfo/techtalk
> >>
> > _______________________________________________
> > Techtalk mailing list
> > Techtalk at linuxchix.org
> > http://mailman.linuxchix.org/mailman/listinfo/techtalk
> >
> 
> 
> _______________________________________________
> Techtalk mailing list
> Techtalk at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/techtalk




More information about the Techtalk mailing list