Solved

Moving mouse to position (X,Y) on screen

Posted on 2008-06-15
2
2,044 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

19 Experts available now in Live!

Get 1:1 Help Now