'telegraphy' as a means of data entry

Fredrik Lundh fredrik at pythonware.com
Sun Sep 12 09:44:03 EDT 2004


Peter Hansen wrote:

> > | > I need to record the respective times of the events in a sequence of
> > | > presses/releases of a particular key on the computer keyboard.

> And Tkinter could certainly do it to, but I don't do Tkinter. :)

in Tkinter, you'll find the event time (in milliseconds) in the time
attribute of the event descriptor:

    from Tkinter import *

    frame = Frame(width=100, height=100)
    frame.pack()
    frame.focus()

    def handler(event):
        print event.time / 1000.0

    frame.bind("<Key>", handler)

    mainloop()

the above only tracks key presses; if you need to track releases
as well, add an extra binding for KeyRelease.

also note that unlike Peter's example, the time attribute contains
the time when the event was generated, not when it reached your
program.

</F>






More information about the Python-list mailing list