Clearing the keyboard buffer (wxPython)

MarcusD stojek at part-gmbh.de
Wed Feb 11 15:28:58 EST 2009


Platform: MSW (XP) Python 2.5 wxPython 2.8
Topic: Clear Keyboard buffer

Hi,
I hope I am not off topic asking a wxpython question.
I'm writing a Score counter for Dart games. The software
shows graphical output on a Canvas and accepts keyboard
input (no buttons, no widgest). A stripped version looks
like that:

self.Bind(wx.EVT_CHAR,OnKeyEvent)
.
.
#--------------
    def OnKeyEvent(self, event):
      k =event.GetKeyCode()
      try:
        z=chr(k)
      except:
        return
      if (z in ["0","1","2","3","4","5","6","7","8","9",.."\r"..]:
        self.keystr +=z
        score=self.CalculateScore(self.keystr)
        self.DisplayScore(score)
        .
        .
      if z== "\r" #enter
        self.SayScore(score)
        self.NextPlayer()
#--------------
    def SayScore(self,number):
      if number > 100:
        a=os.path.join(self.wavpath,"100.wav")
        b=os.path.join(self.wavpath,"%i.wav"%(number-100))
      else:
        a=os.path.join(self.wavpath,"%i.wav"%(number))
        b=""
      sound1 = wx.Sound(a)
      sound2 = wx.Sound(b)
      sound1.Play(wx.SOUND_SYNC)
      if b:
        sound2.HurryupandPlay(wx.SOUND_SYNC)
#--------------

The problem is, that during the voice output all keystrokes
are buffered somewhere and are processed when SayScore is
finished. So I have to clear the keyboard buffer at the end
of SayScore. Something like:

  evt=MagicFetchPendingKeyEventFunction()
  while evt:
    evt=MagicFetchPendingKeyEventFunction()

I was thinking about threading (maybe using delayedresults), but
this might be a little oversized for my problem.
Playing the sound ASYNC doesn't work here.

Any ideas?
Thanks in advance
Marcus





More information about the Python-list mailing list