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.
Sandesh555Asked:
Who is Participating?
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.

StephenJRCommented:
What's the code you are using?
0
Sandesh555Author Commented:
Excel VBA
0
StephenJRCommented:
I meant, can you post the actual code?
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Sandesh555Author Commented:
Here is the code
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

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

0
StephenJRCommented:
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

Dim pos As POINTAPI

Sub x()

GetCursorPos pos

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

End Sub

Open in new window

0

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 :)
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.