screenmouseloc not cutting it

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

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 5:43 pm

tried to find something in the dictionary but no good. I want set the location of the mouse to a specific location in the program. not to the screen. Will i have to go the long way around and get the screen dimensions, the program dimensions, the location of the program on the screen then use some mathematics to work out where in the screen would equal to the place i need in the program?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: screenmouseloc not cutting it

Post by FourthWorld » Fri Oct 13, 2017 5:48 pm

The toLocal and toGlobal functions translate points between coordinate systems.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 5:54 pm

hmmm. i dont see them in the dictionary

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: screenmouseloc not cutting it

Post by Klaus » Fri Oct 13, 2017 5:55 pm

FourthWorld wrote:
Fri Oct 13, 2017 5:48 pm
The toLocal and toGlobal functions translate points between coordinate systems.
@Richard
Maybe you have these functions in your own personal libraries, but these are no build-in LC functions! :D

@Da_Elf
...
## It ain't THAT much math!
put the mouseloc into tML
add the left of this stack to item 1 of tML
add the top of this stack to item 2 of tML
set the screenmouseloc to tML
...

Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: screenmouseloc not cutting it

Post by richmond62 » Fri Oct 13, 2017 6:45 pm

on mouseDown
put the mouseLoc
end mouseDown

will give you the location of your mouse/pointer
on the stack regardless of where your stack
is on screen.

Some people JUST LOVE over-complicating things 8)

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Fri Oct 13, 2017 7:25 pm

Da_Elf wrote:
Fri Oct 13, 2017 5:43 pm
I want set the location of the mouse to a specific location in the program. not to the screen.
I am guessing you want to move the mouse (cursor) to a specific location within the borders of the program window, not get the location of the mouse, Klaus's would be the closest.

Code: Select all

on [message]
	set the screenMouseLoc to the topLeft of this stack 
end  [message]
... of this [object], stack, card, field, button, etc..., get a horizontal and vertical position h,v
... alternately, whatever formula you want to use, based on one or more of the programs rectangle dimensions, left, right, top, or bottom, see 'rect' or 'rectangle' property.
Last edited by bogs on Fri Oct 13, 2017 7:40 pm, edited 1 time in total.
Image

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 7:38 pm

lets say the program is 500x500
i want the mouse moved to the middle of the program then i want to set mouse location to 250,250

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Fri Oct 13, 2017 7:49 pm

Not elegant, but pretty self explanatory, it can be written MUCH shorter, like one line long.

Code: Select all

on mouseUp
   answer "This stacks location is " & the rect of this stack
   put item 1 of the rect of this stack into tmpX
   put item 2 of the rect of this stack into tmpY
   set the screenMouseLoc to (tmpX + 250, tmpY + 250)
end mouseUp
The answer box is in there for you to watch what happens as you move the stack around. Use the return key to OK the answer dialog.
Image

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

Re: screenmouseloc not cutting it

Post by dunbarx » Fri Oct 13, 2017 8:00 pm

When we say "program", do we mean a LiveCode stack? And not some other, er, program?

That seems to be up in the air, hence Richmond's post.

Craig Newman

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: screenmouseloc not cutting it

Post by [-hh] » Fri Oct 13, 2017 8:02 pm

Yet another option is to use
    the globalLoc and the localLoc
for the conversion between global and local coordinates.
shiftLock happens

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: screenmouseloc not cutting it

Post by bogs » Fri Oct 13, 2017 8:06 pm

dunbarx wrote:
Fri Oct 13, 2017 8:00 pm
When we say "program", do we mean a LiveCode stack? And not some other, er, program?

That seems to be up in the air, hence Richmond's post.

Craig Newman
That is true, which is why I should clarify that I am posting ONLY in reference to a stack your making yourself in Lc, NOT for centering on some random program running elsewhere.

I see I also forgot to mention that the 'mouseUp' code in my post could be put anywhere, button, card level, stack level, once you create a stack of the 500, 500 dimension you mentioned, you really don't need to put anything on it.

I see -hh clarified Richards post (I think).
Image

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 9:15 pm

yes. this is indeed trying to use an x,y coordinate based on a stack where 0,0 would be top left of the stack
richards post was to put the mouseloc when i want to set it. looks like bogs put the "unelegant" version i thought might be needed where i need to find the location of the stack in relation to the screen to calculate the position of the mouse on the screen.

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 9:31 pm

the unelegant code works but im trying to use it to find the color of a pixel at a location and im using mousecolor. Plus even though im using lock screen i can still see the pointer buz around the screen. should i just hide the pointer then unhide it?

the below is working now. seemed it didnt delete a group fast enough. whee. things are working....
working on an A* pathfinder.. again

it isnt seeming to work though. when run the dots in the blue area should be black and the rest green.
Attachments
A Star Test3.rar
(1.69 KiB) Downloaded 239 times

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

Re: screenmouseloc not cutting it

Post by dunbarx » Fri Oct 13, 2017 10:01 pm

It is important to know that the "mouseLoc" is read-only. The "screenMouseLoc" can be set. That is why the conversion gadgets exist to find the rect and loc of the card window and adjust.

I have no idea why the mouseLoc cannot be set. It would nice to be able to.

HC had neither. Rinaldi did, though.

Craig

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: screenmouseloc not cutting it

Post by Da_Elf » Fri Oct 13, 2017 10:13 pm

dunbarx wrote:
Fri Oct 13, 2017 10:01 pm
It is important to know that the "mouseLoc" is read-only. The "screenMouseLoc" can be set. That is why the conversion gadgets exist to find the rect and loc of the card window and adjust.

I have no idea why the mouseLoc cannot be set. It would nice to be able to.

HC had neither. Rinaldi did, though.

Craig
thank you. it would be great to be able to set a local position based on stack or even object but i would never know about it since im still using 6.6.2

Post Reply