Page 1 of 1

How can mouseDoubleDown ignore mouseDown?

Posted: Thu Sep 04, 2008 1:22 pm
by gyroscope
Hi, another "polling the mouse" question, I guess...

If I have a button with the script

Code: Select all

on mouseDown
    beep
end mouseDown
    
on mouseDoubleDown
answer "double"
end mouseDoubleDown
the mouseDoubleDown doesn't block the mouseDown message. Is there a way to do this please?

:)

Posted: Fri Sep 05, 2008 12:07 pm
by Janschenkel
How would you expect the engine to predict whether the user is going for a single- or douible-click? You'll have to figure out some sort of shielding.
Here's a quick and dirty idea:

Code: Select all

local sWasDoubleClicked
on mouseDown
  put false into sWasDoubleClicked
  put the doubleClickInterval + 10 into tInterval
  send "singleMouseDown" to me in tInterval milliseconds
end mouseDown
on mouseDoubleDown
  put true into sWasDoubleClicked
  -- do your double down thing here
  answer "Double!"
end mouseDoubleDown
on singleMouseDown
  if sWasDoubleClicked then exit singleMouseDown
  -- do your single down thing here
  beep
end singleMouseDown
Hope this helped,

Jan Schenkel.

Posted: Fri Sep 05, 2008 2:06 pm
by gyroscope
Excellent Jan, thank you! It works a treat.

I tried for two hours yesterday to find a solution; the closest I came to it was to use mouseStillDown in tandem with mouseDoubleClick...your script does the job perfectly.

:)