Solved

Moving mouse to position (X,Y) on screen

Posted on 2008-06-15
2
2,056 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

733 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