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

Patrick Olson compman42 at linuxusers.us
Wed Jun 3 15:41:50 UTC 2015


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
>


More information about the Techtalk mailing list