Tracking the Mouse Loc While Another App is Frontmost
Mac OS 9 Mac OS X Windows Windows

> How can I get this to work:
>
> put the screenmouseLoc into fld "curpos"
>
> ... if the mc app is minimized, IE it's *not* the currently focused app?

Here you go - I made a stack with a button and a field. The script of the button is (watch line wraps):
on mouseUp
  if "trackMouse" is not in the pendingMessages then
    trackmouse
  else
    CancelPending "all"
  end if
end mouseUp

on trackMouse
  put the screenMouseLoc into fld 1
  send "trackMouse" to me in 20 milliseconds
end trackMouse

on CancelPending pMsg
  put the pendingMessages into tPending
  if (pMsg <> "") and (pMsg <> "all") then
    filter tPending with "*," & pMsg & ",*"
  end if
  repeat for each line tMsg in tPending
    cancel item 1 of tMsg
  end repeat
end CancelPending
To test, click the button, and then switch to another app and move it (if necessary) to see the field in your stack... the field should constantly update with the screenMouseLoc even when another app is in the foreground. When you want it to stop, click the button again.

Posted on 3/25/2005 by Ken Ray to the MetaCard list