Mouse Location Coordinates

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Mouse Location Coordinates

Post by kosmo »

Is there an easy way to determine what control (ie. button) is located at a giving mouseloc coordinate?

Thanks,
Kosmo
LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Mouse Location Coordinates

Post by LCNeil »

Hi Kosmo,

I believe the "mouseControl" function is what you are looking for.

Kind Regards,


Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
-
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Mouse Location Coordinates

Post by Klaus »

Hi Kosmo,

and maybe check the new "ControlAtLoc" function in the dictionary.
Never used this so far :D


Best

Klaus
kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Re: Mouse Location Coordinates

Post by kosmo »

Thank you both for responding! I never heard of the ControlAtLoc...but this is exactly what I am looking for.

Appreciate your help!
Kosmo
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Mouse Location Coordinates

Post by Klaus »

Hi Kosmo,

I think "ControlAtLoc" has been added in version 6.5!


Best

Klaus
kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Re: Mouse Location Coordinates

Post by kosmo »

The ControlAtLoc is working great except when there is no control at the location. The program fails. I was hoping the program would just send back a empty value. I did find a way around this by creating a label field the size of the stack. Not sure if there is a better way to take care of this?

Thanks
Kosmo
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Mouse Location Coordinates

Post by Klaus »

Hi Kosmo,

just tested here and -> controlAtLoc(tLoc) returned EMPTY in that case?
Please post your script if possible.


Best

Klaus
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Mouse Location Coordinates

Post by dunbarx »

ControlAtLoc returns empty for me if there is no control at the specified loc.

Craig
kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Re: Mouse Location Coordinates

Post by kosmo »

Craig,

I am using the following code:

if the name of (controlAtLoc(the mouseLoc)) contains "Button_" then
answer "button"
else
exit mousedown
end if

If I am on a button, I will get the "button" message. If I don't have a control at the location, I get:

card "card id 1002": execution error at line 3 (Chunk: error in object expression), char 16

I am on version 6.5.2

Thanks for any help!
Kosmo
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Mouse Location Coordinates

Post by dunbarx »

Hi.

You cannot exit mouseDown in a mouseUp. The controlAtLoc function returns the string "Control" and the control number. When you ask for the name of the result of that function, with no control in that loc, you are essentially asking for:

the name of empty.

LC considers this to be in the same category as bad cheese to a sensitive stomach.

But the value of this is to understand how LC evaluates the various things thrown at it. Cool, no?

Craig
kosmo
Posts: 15
Joined: Mon Feb 17, 2014 6:05 pm

Re: Mouse Location Coordinates

Post by kosmo »

Craig,

Thanks for the explanation. I changed my logic a bit which now works...

on mousedown
if (controlAtLoc(the mouseLoc)) <> empty then
(do my code)
else
exit mousedown
end if
end mousedown

Appreciate all your help!
Kosmo
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Mouse Location Coordinates

Post by dunbarx »

Kosmo.

Right!!! Now you are getting it.

The evaluation process within LC is one of its most powerful and endearing features. It allows, once you get used to it, terrific intuitive communication between the way humans think and the way the engine processes those thoughts. You will use this more and more, especially when you pass parameters from one handler to another.

But at the base level, like here, it must be learned by heart.

Umm. Any way you can shorten that last handler?

Craig
Post Reply