[visionegg] pygame mouse handling within VE

  • From: Christoph Lehmann <lehmann@xxxxxxxxxxxx>
  • To: visionegg@xxxxxxxxxxxxx
  • Date: Mon, 18 Aug 2003 14:35:53 +0200

Hi
I found a bug in my visionegg_fmri code...

using an event queue approach after e.g. 120 mouse presses, no mouse
button presses were logged any more...

I think this has to do with the fact, that without calling EVERY event,
events such as MOUSEBUTTONUP or MOUSEMOVE will remain in the queue and
the queue seems to have a certain maximum length.

here the old code, calling only MOUSEBUTTONDOWN events (and therefore
only these events are removed from  the queue )
--

        if mouse_enabled:
            # log the mouse response (which button, RT, precision)
            for event in pygame.event.get(pygame.locals.MOUSEBUTTONDOWN): 
                if event.button == 1:                            #left
                    rt_left = 1000 * (VisionEgg.time_func() - trial_onset)
                    response_log.append('L')                         #left
                elif event.button == 3:                          #right
                    rt_right = 1000 * (VisionEgg.time_func() - trial_onset)
                    response_log.append('R')                         #right



--

the new code: 
    if mouse_enabled:
        # log the mouse response (which button, RT, precision)   
        for event in pygame.event.get():
            if event.type == MOUSEBUTTONDOWN and event.button == 1:             
               #left
               response_log.append('L')                         #left
               response_log_list.append(response_log)           #append last 
response log (since we want only one response log per trial
               response_log = []                                    #clear 
response_log
            elif event.type == MOUSEBUTTONDOWN and event.button == 3:           
               #right
               response_log.append('R')                         #right
               response_log_list.append(response_log)           #append last 
response log (since we want only one response log per trial
               response_log = []                                    #clear 
response_log
              
--
I go through all pygame events... therefore making sure, that alle events are 
removed from the queue every time I call the for loop (almost every frame)

Andrew: Do you recommend it to do it like I did now (event queuing and going 
through all events) or would you recommend state checking as :
mouse.get_pressed([0])  #if right mouse button is right now down

The question is: how long after a mouse button down event, this 
mouse.get_pressed([0]) call would return a '1'. Means: is there a risk of not 
getting some 
mouse button down events when between two such calls is more than e.g. 16ms 
(could be the case when waiting vor vsync)...


what do you think is better?

Many thanks

Christoph


-- 
Christoph Lehmann <lehmann@xxxxxxxxxxxx>
University Hospital of Clinical Psychiatry

======================================
The Vision Egg mailing list
Archives: //www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html

Other related posts: