moving the mouse to a specific position

Just starting out? Need help? Post your questions and find answers here.
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

moving the mouse to a specific position

Post by Blue »

I know how to figure out where the mouse is, on the screen. PB provides clear, specific and simple functions to obtain those coordinates.

What i can't figure is how to move the mouse to a specific position.

I have a window centered in the screen. I want to make sure that the mouse pointer is located smack in the middle of that window when my app launches. I thought that would be a no-brainer, but no. I just can't find a PB function that allows me to position the mouse in the middle of my window.

How do i do that ?
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: moving the mouse to a specific position

Post by Blue »

Just found the answer.... see here
As is often the case, my search terms were not adequate for the task.

The solution lies with DisplayPopupMenu(#Menu, WindowID [, x, y])
Thank you PB for a simple effective solution.
Too bad it takes so much work to find it !
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: moving the mouse to a specific position

Post by Lunasole »

Blue wrote: Thu Mar 30, 2023 8:10 pm Just found the answer.... see here
As is often the case, my search terms were not adequate for the task.

The solution lies with DisplayPopupMenu(#Menu, WindowID [, x, y])
Thank you PB for a simple effective solution.
Too bad it takes so much work to find it !

Haha using DisplayPopupMenu for this is funny of course.
The PB (as well as others) doesn't have such functions (at least not for a desktop mode, if using directX/opengl rendering then it's another).
Should use OS functions like this at Windows

Code: Select all

ExamineDesktops()
Global DeskW = DesktopWidth(0)
Global DeskH = DesktopHeight(0)

Define Action.INPUT
Action\type = #INPUT_MOUSE
Action\mi\dwFlags = #MOUSEEVENTF_MOVE|#MOUSEEVENTF_ABSOLUTE|#MOUSEEVENTF_VIRTUALDESK

Define CX = 200
Define CY = 500

Action\mi\dx = 65535.0 * (cX/DeskW) ; #MOUSEEVENTF_ABSOLUTE: dx and dy contain normalized absolute coordinates between 0 and 65,535
Action\mi\dy = 65535.0 * (cY/DeskH)

SendInput_(1, Action, SizeOf(INPUT))
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: moving the mouse to a specific position

Post by BarryG »

DisplayPopupMenu? But that'll open a menu where you move the mouse with it.

For Windows, you can move the mouse somewhere as easily as this (no menu needed):

Code: Select all

SetCursorPos_(x,y)
User avatar
Blue
Addict
Addict
Posts: 864
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: moving the mouse to a specific position

Post by Blue »

Thanks BarryG and Lunasole
for paying attention to my frivolous rantings.

Much appreciated !

Don’t laugh too hard at me, BarryG. What I was * really * looking for is what I ended up finding, albeit strictly by chance : a way to display a pop-up menu at a specific position. As mentioned, precision and clarity of purpose often end up sorely missing from my search expeditions… as well as from my thought process, it seems !

The simplicity of your proposed code is admirable and duly noted; it’s going right away into my quick reference tips.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
SMaag
Enthusiast
Enthusiast
Posts: 110
Joined: Sat Jan 14, 2023 6:55 pm

Re: moving the mouse to a specific position

Post by SMaag »

do you search for this PB-Command

MouseLocate(x, y)
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: moving the mouse to a specific position

Post by Demivec »

SMaag wrote: Fri Mar 31, 2023 10:48 am do you search for this PB-Command

MouseLocate(x, y)
That function's description is: "Changes the absolute position (in pixels) of the mouse in the current screen."

It is a low level function for use on screens and windowed screens but not on window space outside of a screen.
Post Reply