Page 1 of 1

Odd mouseUp/mouseDown behavior

Posted: Tue Dec 12, 2023 10:13 pm
by dunbarx
All.

I was teaching a very newbie about LC, and made a simple stack to show how messages are sent and trapped. But in the first five minutes of building and demonstrating a simple button I ran into an anomaly that was embarrassing. The gadget I made just did not work perfectly.

Almost, but not perfectly. Embarrassing.

In the attached stack if one clicks on the button over and over one is supposed to see a random animal on "mouseDown", and a random number on mouseUp.

Code: Select all

on mouseup
   put random(999) into field 1
end mouseup

on mouseDown
   put any word of "cat dog bird worm roach lion" into fld 1
end mouseDown
But if one plays around a bit, with relatively rapid clicks of the mouse and including holding the mouse down for just a bit each press, the mouseDown handler will not fire about 20% of the time. This is noticeable. I am an expert, and can catch and hold this behavior after only a few full clicks.

If one catches one of these, then while holding the mouse down the random number from the previous mouseUp remains in the field, all day if I let it. If I finally release the mouse, the animal shows up for an instant and the the random number appears. The mouseDown message is sent only when I release the mouse, and then the mouseUp message is finally sent.

It never does the the other way around. If one waits even a half second between successive clicks, everything always works just fine.

What is freezing the mouseDown message when pressing quickly? I included a few "wait 0 (or 1 or 2) with messages" lines but they did nothing.

Craig
mouseDown anomaly.livecode.zip
(1.08 KiB) Downloaded 52 times

Re: Odd mouseUp/mouseDown behavior

Posted: Tue Dec 12, 2023 10:53 pm
by SparkOut
Is this to do with the mouseDoubleDown and mouseDoubleUp messages being invoked?
What if you move the action to another "doDownStuff" handler, and called doDownStuff from both mouseDown and mouseDoubleDown, and doUpStuff from the Up handlers?

Re: Odd mouseUp/mouseDown behavior

Posted: Wed Dec 13, 2023 12:33 am
by dunbarx
Sparkout.

You made my day. I had set the doubleClickInterval to 100 long ago to prevent just this sort of issue, and never thought of it again. Apparently I was showing off to the newbie by clicking quickly to swap the field contents.

I was getting so good at catching this thing that I was double-clicking faster than that. Setting the interval to 20 fixed it.

And yes, the message watcher showed a mouseDoubleDown message now and then. But never mouseDoubleUp, which actually makes sense.

I guess the engine waits the interval before it will even consider mouseDown.

Craig

Re: Odd mouseUp/mouseDown behavior

Posted: Wed Dec 13, 2023 12:39 am
by bn
SparkOut wrote:
Tue Dec 12, 2023 10:53 pm
Is this to do with the mouseDoubleDown and mouseDoubleUp messages being invoked?
following SparkOut's hint
What happens if you set the doubleClickInterval to 0, for me it cures it. Whereas setting the doubleClickInterval to 200 makes it worse.
I blocked the wait stuff in your handlers.

Kind regards
Bernd

Re: Odd mouseUp/mouseDown behavior

Posted: Wed Dec 13, 2023 3:51 pm
by dunbarx
Bernd.

Making the interval longer will allow the mouseDoubleDown message to be sent more often. Making it 0 will likely prevent it from ever being sent.

I had thought that 100 (milliseconds), the value I set long ago, since I almost never use it, would effectively kill it. But fooling around here I was faster.

If I do actually need it, I still use an old HC trick I invented long ago:

Code: Select all

on mouseUp
   wait 20 (ticks here)
   if the mouseClick then put random(999)
end mouseUp
Old-fashioned, I know. I should change.

Craig

Re: Odd mouseUp/mouseDown behavior

Posted: Wed Dec 13, 2023 10:16 pm
by SparkOut
AFAIK (and how far I know is measured in millimetres not miles) the doubleclickInterval is .... necessary to be understood, while the important thing is (I'm sure Jwack can expound) to fire the required handler when due, whether by double or single mouse event.
Rather than adjusting the doubleclickInterval, what results do you get with

Code: Select all

on mouseDoubleDown
  doMouseDownStuff
end mouseDoubleDown

on mouseDown
  doMouseDownStuff
end mouseDown

on doMouseDownStuff
  put "Down events happened"
end doMouseDownStuff
(Trap similar "up" mouse events too)

Re: Odd mouseUp/mouseDown behavior

Posted: Thu Dec 14, 2023 12:35 am
by dunbarx
Sparkout.

The doubleClickInterval rules how "mouseDown" and "mouseDoubleDown" interact. If you have both handlers in a script and the interval is greater than your "click rate", then both will fire. If the interval is very small, like less than about 75 (milliseconds) then only mouseDown will fire. This because mouseDoubleDown is never allowed to get off the ground.

The interval is a sort of "wait a bit and see if there is a second click" gadget. If the "wait" time passes, no mouseDoubleDown message is sent. The second click is ignored.

For me, I really have to try if the interval is less than about 75;

Code: Select all

on mouseDoubleDown
add 1 to fld 1
end mouseDoubleDown

on mouseDown
  add 1 to fld 2
end mouseDown
If the interval is great enough, and one double clicks quickly, you get 2 added to fld 2 and 1 added to fld 1 (one mouseDoubleDown and two mouseDown). If not , you only get 2 added to fld 2 (two mouseDown).

Craig