'telegraphy' as a means of data entry
Cliff Wells
clifford.wells at comcast.net
Mon Sep 13 02:26:05 EDT 2004
On Sun, 2004-09-12 at 15:44 +0200, Fredrik Lundh wrote:
> 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:
> also note that unlike Peter's example, the time attribute contains
> the time when the event was generated, not when it reached your
> program.
Here's a more complete example in wxPython. Like the effbot's example,
this uses the time the event was generated. I didn't really feel like
examining all the possible places a wav file might exist on all
platforms, but here's a start:
import wx
SOUND = {
'__WXMSW__': 'c:/winnt/media/ding.wav',
'__WXGTK__': '/usr/share/sounds/generic.wav',
}[wx.Platform]
class Panel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.ts = None
self.sound = wx.Sound(SOUND)
if not self.sound.IsOk():
self.sound = None
print "Your sound file is bad."
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
def OnKeyDown(self, evt):
if evt.GetKeyCode() == wx.WXK_DELETE:
t = evt.GetTimestamp() / 1000.0
if self.ts is not None:
print "time between", t - self.ts
self.ts = t
if self.sound:
self.sound.Play(wx.SOUND_ASYNC)
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'test')
p = Panel(self, -1)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = Frame()
frame.Show()
app.MainLoop()
Regards,
Cliff
--
Cliff Wells <clifford.wells at comcast.net>
More information about the Python-list
mailing list