Page 1 of 1

Clearing a message buffer (mouse and keypress)

Posted: Tue Apr 22, 2008 5:42 pm
by Josh
Hi all,

My program involves users to make responses via keypresses and mouseclicks. The problem is if they use either repeatedly, then they receive a string of feedbacks, with only the first one being relevant. How do I ensure that the first mouse click is the only one registered (until I'm ready for the next mouseclick) and the same question for keypress. Script is below:

on keyDown theKey
put theKey into thisKey
if thisKey="d" or thisKey="k" then

on mouseUp pMouseBtnNum
if mouseClickOK then buzz
else exit mouseUp
end mouseUp

on mouseUp pMouseBtnNum
if mouseClickOK is false then exit mouseUP
put "Rect3" into clickedRect
foilClicked
end mouseUp

I could do it with a boolean I suppose, but I imagine there is a more elegant way.

Josh

Posted: Tue Apr 22, 2008 5:49 pm
by Janschenkel
Hi Josh,

You could try using the 'flushEvents' function. To eat all the events that happened since your script started, use:

Code: Select all

on mouseUp
  -- do my normal processing
  ...
  -- setup for the next question
  ...
  -- now eat all user events in the queue
  get flushEvents("all")
end mouseUp
Hope this helped,

Jan Schenkel.

Posted: Wed Apr 23, 2008 8:31 am
by Mark
Hi,

Flushevents won't do any good in this case. Using a variable with a boolean is the way to go.

Best,

Mark