Get the current position of the Mouse in X and Y axis.

Hi team,

In question# Q_27479868, I had asked as to how do I click on a specific part of the screen for any application.  I got the answer and it is work great.

Now every time I want to use this solution, I have to give two differnt values for a specific location of the screen.  The right part of the screen is got though trial and error.  Now I want a solution were when I run the solution, it should pop up or update somewere the current location numbers (x and y axis) of the mouse.

Can you please help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What's the code you are using?
Sandesh555Author Commented:
Excel VBA
I meant, can you post the actual code?
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Sandesh555Author Commented:
Here is the code

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Sub Test()
    a = LeftClick(500, 200)
End Sub

Function LeftClick(ByVal x As Long, ByVal y As Long)
    SetCursorPos x, y
    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Function

Open in new window

Do you mean like this?
Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


Sub x()

GetCursorPos pos

MsgBox "Cursor is at:" & vbNewLine & "x=" & pos.x & vbNewLine & "y=" & pos.y

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sandesh555Author Commented:
Perfect :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.