mouseDown/mouseUp problem

J. Landman Gay jacque at hyperactivesw.com
Wed Mar 16 13:40:45 EST 2005


On 3/15/05 9:16 PM, James Spencer wrote:

> I've got a button which, when it is pressed and held, I want to do some 
> things (brief and repetitive) and then do some other things once it is 
> released.  I've got handlers in the button script:
> 
> on mouseDown
>     repeat while the mouse is down
>         -- do stuff repeatedly while mouse is down
>     end repeat
>     -- do some quick cleanup code before exiting
> end mouseDown
> 
> on mouseUp
>     -- do stuff now that the button as been released
> end mouseUp
> 
> My mouseUp handler is not being called.  Well that's not really true; it 
> has been called exactly once in maybe a couple of dozen trials.

This all used to work the same as it does in HyperCard back in the 
Beginning Of MC Time, but the behavior changed a few years ago. Tracking 
mouseup within a loop was CPU-intensive and Scott Raney wanted to change 
the behavior to make MetaCard more efficient. There was some discussion 
on the mailing list about it (and about how it would break legacy 
stacks,) but eventually it was decided that mouseup would no longer be 
cached in the event queue; instead it would only be sent if the mouse 
were actually going up at exactly the moment the script encountered the 
test command.

The HC-style loop polling is strongly discouraged in MC/Revolution. It 
was sort of okay to do in OS 9 because there wasn't really any 
multi-tasking, but with modern OS architecture, polling the mouse can 
bring some systems to their knees if the loop goes on long enough.

So what you need to do instead, which is much more efficient and 
friendly, is this:

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

I think it was Chipp who posted a briefer response with the same 
technique, but this web page may give you some additional ideas.


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


More information about the use-livecode mailing list