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 » Thu Feb 20, 2014 7:53 pm

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 » Thu Feb 20, 2014 8:13 pm

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: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Mouse Location Coordinates

Post by Klaus » Thu Feb 20, 2014 8:14 pm

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 » Thu Feb 20, 2014 8:20 pm

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: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Mouse Location Coordinates

Post by Klaus » Thu Feb 20, 2014 9:38 pm

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 » Fri Feb 21, 2014 4:30 pm

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: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Mouse Location Coordinates

Post by Klaus » Fri Feb 21, 2014 4:35 pm

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: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Mouse Location Coordinates

Post by dunbarx » Fri Feb 21, 2014 6:58 pm

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 » Fri Feb 21, 2014 7:36 pm

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: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Mouse Location Coordinates

Post by dunbarx » Fri Feb 21, 2014 9:52 pm

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 » Fri Feb 21, 2014 9:55 pm

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: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Mouse Location Coordinates

Post by dunbarx » Fri Feb 21, 2014 10:10 pm

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