mouseControl problem

J. Landman Gay jacque at hyperactivesw.com
Wed Mar 18 16:39:56 EDT 2009


DunbarX at aol.com wrote:
> I am rewriting the "ss" function in HC. Because it is there.
> 
> Whereas this works fine (in a button script):
> 
> on mouseUp
>  set cursor to plus
>     repeat until the optionKey is down
>        if the mouseClick then put the mouseLoc
>     end repeat
> end mouseUp
> 
> I cannot get this to work at all:
> 
> on mouseUp
>  set cursor to plus
>     repeat until the optionKey is down
>        if the mouseClick then put the mouseControl 
>     end repeat
> end mouseUp
> 
> Only changed one word.
> 
> I can get mouseLocs at each click all around the stack. I can only get the 
> mouseControl for the object that contains the script itself. Something about the 
> mouseControl?

 From the docs: "If the mouse button is down, the mouseControl function 
returns the control that was clicked, even if the mouse has moved to 
another control."

Since "the mouseclick" causes a mousedown, mouseWithin, mouseUp 
sequence, and since your repeat loop is very short and tight, the 
mousecontrol may be triggering on the original mousedown only. I'm 
guessing though.

A better method might be to use a flag and the mousemove message:

In a button:
on mouseup
    send "getmousecontrol" to this cd in 1
end mouseup

In the card or stack:

local flag

on getmousecontrol
    put true into flag
end getmousecontrol

on mousemove x,y
    if the optionkey is down then put false into flag
    if flag then put the mousecontrol
end mousemove

There are some other reasons not to poll the mouse inside a repeat loop. 
One reason is that the right values aren't always returned, because the 
condition of the mouse is only checked at the exact moment the line of 
script is running. In long loops, a mouseclick may not trigger at all if 
the mouse is clicked while a different command inside the loop is running.

More here:

<http://www.hyperactivesw.com/polling.html>

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list