Constraining the pointer within a rect

Howard Bornstein howard.bornstein at gmail.com
Thu Aug 17 11:40:20 EDT 2006


This script seems to work with adequate performance:

on mousemove mh,mv
  if the hilite of btn "constrain" is true then

    if mh <= the left of fld "container" then
      set the screenmouseloc to the globalloc of (the left of fld
"container", mv)
    end if

    if mh >= the right of fld "container" then
      set the screenmouseloc to the globalloc of (the right of fld
"container", mv)
    end if

    if mv <= the top of fld "container" then
      set the screenmouseloc to the globalloc of (mh,the top of fld
"container")
    end if

    if mv >= the bottom of fld "container" then
      set the screenmouseloc to the globalloc of (mh,the bottom of fld
"container")
    end if

  end if
end mousemove


Note two things:

1) The button "Constrain" needs to be within the field "Container" or you'll
never be able to get out. :-)

2) It is possible to move the mouse out of the rect for brief moments, but
then it pops back into the rectangle. I'm assuming it's a function of
slipping out between a mousemove scan.



-- 
Regards,

Howard Bornstein
-----------------------
www.designeq.com



More information about the use-livecode mailing list