Can I get the name of an object at the clickloc?

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Can I get the name of an object at the clickloc?

Post by jacque » Mon May 02, 2022 5:29 am

Stam's way will work, there are lots of ways to do things in LC. To avoid needing a script local variable, I tried this:

In the button that selects the dropper tool:

Code: Select all

on mouseUp
  lock cursor
  set the cursor to 1005
end mouseUp
And in the card script:

Code: Select all

on mouseUp
  if the cursor is 1005 then
    put the mousecolor -- or into a variable
    set the cursor to empty -- restores the default
    unlock cursor
  else
    pass mouseUp
  end if
end mouseUp
Since LC doesn't have a dropper cursor, I imported a custom image whose ID was 1005. I set the hotspot of the image to the appropriate spot in the image.

Since your graphics are a single color, getting the backgroundColor should be fine. The mouseColor will return the exact pixel color under the mouse, which is useful for images with multiple colors. Either way will work in this case.

If you will need different cursors for different tools, expand the card handler to account for each. This method assumes that none of the graphics have mouseUp handlers; if they do, pass the mouseUp in the graphic so the card handler will get it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Can I get the name of an object at the clickloc?

Post by jacque » Mon May 02, 2022 5:33 am

stam wrote:
Mon May 02, 2022 2:56 am
As a user, i would expect software to allow me to cancel an eyedropper tool by hitting the escape button.
I hadn't thought of that. So both our methods would need an escapeKey handler as well. Good thought.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Can I get the name of an object at the clickloc?

Post by richmond62 » Mon May 02, 2022 10:55 am

SShot 2022-05-02 at 12.54.42.png
-
It never ceases to amaze me what a continuing education these forums are. 8)
Last edited by richmond62 on Mon May 02, 2022 11:11 am, edited 1 time in total.

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Can I get the name of an object at the clickloc?

Post by stam » Mon May 02, 2022 10:58 am

Thanks Richmond - exactly that was is in my suggestion above.

But it’s hard to trigger on escapeKey if all the code is in a mouseUp handler…. Hence my approach of putting the code in the card script.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Can I get the name of an object at the clickloc?

Post by richmond62 » Mon May 02, 2022 11:10 am

Well, yes, the problem is that unlike shiftKey and ctrlKey where you can do stuff like this:

Code: Select all

on mouseUp
if shiftKey() is down then
---- do something
else
---- do something else
end if
end mouseUp
doing that sort of thing with escapeKey does not work.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Can I get the name of an object at the clickloc?

Post by richmond62 » Mon May 02, 2022 11:30 am

And, thinking about that, it might be a thought to badger LiveCode central to change the language so that
these types of things are possible:

arrowKey() is down

escapeKey() is down

functionKey() is down

-
Bkeys.jpg

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Can I get the name of an object at the clickloc?

Post by stam » Mon May 02, 2022 11:39 am

richmond62 wrote:
Mon May 02, 2022 11:10 am
Well, yes, the problem is that unlike shiftKey and ctrlKey where you can do stuff like this:

Code: Select all

on mouseUp
if shiftKey() is down then
---- do something
else
---- do something else
end if
end mouseUp
doing that sort of thing with escapeKey does not work.
Quite... it would only be feasibly is you clicked the mouseButton while holding down the escapeKey so no good.

If one did want to keep all the code in the mouseUp handler, one way around this would be to have a global variable keep track if sampling or not.
In a card (or stack) script you could set this to false in the on escapeKey handler and check this in the mouseUp handler. Or you could remove the pending messages from the message queue in the escapeKey handler. But logistically for me it's simpler to separate the code into the card script...

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Can I get the name of an object at the clickloc?

Post by richmond62 » Mon May 02, 2022 2:43 pm

I wonder what the rawKey code for the ESC key might be.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can I get the name of an object at the clickloc?

Post by dunbarx » Mon May 02, 2022 3:13 pm

Richmond

65307 (escape)

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can I get the name of an object at the clickloc?

Post by dunbarx » Mon May 02, 2022 4:08 pm

One has to be careful when using a "mouseUp" handler in the same world as another handler that checks to see if the mouse is down. Or at least I do. The following never exits though it seems it ought to:

Code: Select all

on mouseUp
   set the cursor to cross
   getColor
end mouseUp

on getColor
   if the mouse is down then
      put the mouseColor into fld 1
      set the cursor to arrow
      exit to top
   else
      send "getColor" to me in 1
   end if
end getColorr
Clicking the mouse to find the mouseColor also "restarts" the mouseUp handler itself. Lots of ways around that, of course.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can I get the name of an object at the clickloc?

Post by dunbarx » Mon May 02, 2022 4:12 pm

Richmond
arrowKey() is down
escapeKey() is down
functionKey() is down
You are asking that LC create new functions where now we have messages. We do have some, of course, like "optionKey()".

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Can I get the name of an object at the clickloc?

Post by richmond62 » Mon May 02, 2022 4:12 pm

SShot 2022-05-02 at 18.11.08.png
Attachments
DEVILS ISLAND.livecode.zip
Stack.
(18.49 KiB) Downloaded 68 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Can I get the name of an object at the clickloc?

Post by richmond62 » Mon May 02, 2022 4:14 pm

You are asking that LC create new functions where now we have messages. We do have some, of course, like "optionKey()".
Whoops, have I committed a cardinal sin? I do hope so. 8)
65307 (escape)
Hilarious: that was a rhetorical wonder.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can I get the name of an object at the clickloc?

Post by dunbarx » Mon May 02, 2022 4:40 pm

I commit ordinal sins only.

I tried to emulate trapping the escape key in the midst of a handler doing its thing. Not easy. I could not make the "rawkeyDown" message fire in the middle of a running handler, and that was the only thing I could think of to try to insinuate into the flow.

Others may have more clever ideas, but without a function I don't see a way right now.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Can I get the name of an object at the clickloc?

Post by richmond62 » Mon May 02, 2022 4:51 pm

How about making "all the other stuff" happen
when one presses the ESC key?

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”