# Is there a way to clear the mouse event buffer?

**URL:** <https://psychtoolbox.discourse.group/t/is-there-a-way-to-clear-the-mouse-event-buffer/950>\
**Category:** Uncategorized\
**Created:** [June 1, 2011, 6:30pm UTC](https://psychtoolbox.discourse.group/t/is-there-a-way-to-clear-the-mouse-event-buffer/950 "2011-06-01T18:30:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [June 1, 2011, 6:30pm UTC](https://psychtoolbox.discourse.group/t/is-there-a-way-to-clear-the-mouse-event-buffer/950/1 "2011-06-01T18:30:12Z")

</div>

Platform: OSX  
  
Scenario:  
  
I'm writing an interface that allows panning (with grab and drag) and zooming (with the mouse wheel) of an image larger than the window.  
  
Initially, I found that the click-drag aspect would be unresponsive for a noticeable delay after zooming had completed. Checking the code in GetMouseWheel, I surmised that the while loop was at fault. So I cobbled together a new function for mouse queries that lumped together the buttons, coordinates, and wheel-delta data, and replaced the while loop with a single iteration of the low-level HID report.  
  
Having done this, the click-drag was now appropriately responsive no matter how recently a zoom had completed, but - predictably - the zooming was now sporadically laggy / jumpy. This was particularly the case when attempting to zoom immediately following a click-drag event. Presumably the mouse buffer is loaded up with garbage that needs to clear out of the queue before the wheel events can be processed.  
  
Question:  
  
My ideal solution would be to be able to clear the mouse event buffer (for instance, at the end of each mouse query), but I can't find a way to do that. Any thoughts?  
  
Alternatively, and also desirable, can anyone point me to documentation that clarifies the PsychHID('GetReport', ...) functionality  in particular what to expect as output and how to interpret it?  
  
Finally, the existing documentation for PsychHID suggests that there is a significant overhead cost from a diagnostic printf. If anyone knows of a way to suppress that, I would be happy to hear it (I can't readily butcher the existing code since it's MEX not .m).  
  
Thanks in advance,  
-Grayden

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [June 3, 2011, 8:36pm UTC](https://psychtoolbox.discourse.group/t/is-there-a-way-to-clear-the-mouse-event-buffer/950/2 "2011-06-03T20:36:29Z")

</div>

As I understand it, FlushEvents only actually supports keyboard events. From the help file:  
  
"FlushEvents will accept all arguments, but only 'keyDown' (or no  
 argument at all) removes keypress events. Events other than keypress  
 events are not supported."  
  
-Grayden  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "gennaer" \<gennaer@...\> wrote:  
> \>  
> \> Have you tried FlushEvents?  
> \>
