Mouse messages while down

Scott Rossi scott at tactilemedia.com
Sun Mar 18 04:35:01 EDT 2007


Recently, Sarah Reichelt wrote:

> It seems that the mouseControl should be able to report where
> the mouse is without me having to check it manually. But mouseControl
> gets stuck when you click down and never changes until the mouse comes
> up again.

You may not be able to check the mouseControl while the mouse is pressed,
but you *can* check the mouse position on mouseMove while the mouse is down.

The main reason to avoid polling is because you have 400 objects to check --
it could be demanding and possibly prevent stuff from executing.  But you
could establish a coordinate grid defined by the rects of the buttons, and
monitor the X,Y in a mouseMove handler.

Assume a grid of btns on a card:

a1 b1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3


Put the following in the card script (actual mouseMove code would be more
efficient):

local W,H,L,T,gridRect,checkPos
on mouseDown
  put width of btn 1 into W
  put height of btn 1 into H
  put left of btn 1 into L
  put top of btn 1 into T
  put L,T,(L+4*W),(T+3*H) into gridRect
  put true into checkPos
end mouseDown

on mouseMove X,Y
  if not checkPos then pass mouseMove
  if not (X,Y is within gridRect) then
    put ""
    pass mouseMove
  end if
  if X < (L+4*W) then put "d" into btnX
  if X < (L+3*W) then put "c" into btnX
  if X < (L+2*W) then put "b" into btnX
  if X < (L + W) then put "a" into btnX
  #
  if Y < (T+3*H) then put 3 into btnY
  if Y < (T+2*H) then put 2 into btnY
  if Y < (T + H) then put 1 into btnY
  put "Mouse is within button" && btnX & btnY
end MouseMove

on mouseUp
  endCheck
end mouseUp

on mouseRelease
  endCheck
end mouseRelease

on endCheck
  put false into checkPos
  put ""
end endCheck

This should monitor the mouse position relative to each button.
Hope this helps.

Regards,

Scott Rossi
Creative Director
Tactile Media, Multimedia & Design
-----
E: scott at tactilemedia.com
W: http://www.tactilemedia.com





More information about the use-livecode mailing list