Solved

Moving mouse to position (X,Y) on screen

Posted on 2008-06-15
2
2,047 Views
Last Modified: 2012-05-05
I have some trouble getting the mouse to point at a specific position (X,Y) on the screen. I tried using this, but haven't found a solution that works in vb.net (i use Visual Studio 2005)

 Private Declare Function ClientToScreen Lib "user32" _
    (ByVal hwnd As Long, ByVal lpPoint As POINTAPI) As Long
    Private Declare Function SetCursorPos Lib "user32" _
    (ByVal x As Long, ByVal y As Long) As Long

Any thoughts ?
0
Comment
Question by:soriega
2 Comments
 
LVL 35

Accepted Solution

by:
torimar earned 125 total points
ID: 21788310
I couldn't make sure that this will work as I don't have VB.Net installed, but you may try.

Note:
MoveMouse (X,Y) will either refer to an absolute screen position, or to the difference between the target position and the current cursor position. I'm afraid I can't guess which.




Declare Auto Function mouse_event Lib "user32.dll" (ByVal dwflags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As Integer) As Integer
 

Public Const MOUSEEVENTF_MOVE = &H1
 

Public Sub MoveMouse(ByVal xMove As Integer, ByVal yMove As Integer)

mouse_event(MOUSEEVENTF_MOVE, xMove, yMove, 0, 0)

End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 21789076
You don't need to use the WinAPIs for this...

Just use:

    Cursor.Position = New Point(500, 350)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open a word document 23 33
Definitions and default visual studio colors 5 58
C# Offline Apllication 5 54
I need help converting a bitmap to an image in VB.Net 1 0
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now