How can mouseDoubleDown ignore mouseDown?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

How can mouseDoubleDown ignore mouseDown?

Post by gyroscope » Thu Sep 04, 2008 1:22 pm

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?

:)

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Fri Sep 05, 2008 12:07 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Fri Sep 05, 2008 2:06 pm

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.

:)

Post Reply