Click on given coordinates

TGoC

New member
Joined
Jan 27, 2006
Messages
4
Programming Experience
1-3
Hey guys,

How can make VB.NET 2005 express, click at certain given coordinates?

I appreciate any help.
 
On a form of your own?
Is the receiver your own application?
If not, what kind of application has to receive the mouseclicks?
What exactly are you trying to achieve?
 
I want to do a single click on coordinates : 400 (from the left) and 300 (from the height) wich is called by a button in the same form... :)
 
I Just want it that when the timer ticks that it'll click at coordinates (Left offside 600 and Top offside 300) In same form if it would be possible to do it another way i wouldn't be asking how to autoclik at certain given coordinates huh :p
 
I guess i'm just being stupid.

I know nothing of VB.net, i will be going some good tutorials over till i get it.

Anyway thanks for the help provided. :)
 
You can use SendMessage Win32 API method passing it the handle to the button in hwnd and BM_CLICK constant in wMsg. To do this, add this stuff:
VB.NET:
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
  ByVal hwnd As Int32, _
  ByVal wMsg As Int32, _
  ByVal wParam As Int32, _
  ByVal lParam As Int32) As Int32
Const BM_CLICK As Int32 = &HF5
then make the call from a method so:
VB.NET:
SendMessage(Me.Button2.Handle.ToInt32, BM_CLICK, 0, 0)
 
...but you asked to click at certain coordinates, ok, there is no click to send then but you can send mouse down plus mouse up at same coordinates. Perhaps you even only need to mouse down...
These are the declares:
VB.NET:
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
  ByVal hwnd As Int32, _
  ByVal wMsg As Int32, _
  ByVal wParam As Int32, _
  ByVal lParam As Int32) As Int32
Const WM_LBUTTONUP As Int32 = &H202
Const WM_LBUTTONDOWN As Int32 = &H201
Function makeint32(ByVal LoWord As Integer, ByVal HiWord As Integer) As Int32
  Return (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
This how you call it from a method:
VB.NET:
SendMessage(Me.Handle.ToInt32, WM_LBUTTONDOWN, 0, makeint32(x, y))
SendMessage(Me.Handle.ToInt32, WM_LBUTTONUP, 0, makeint32(x, y))
The x/y have to be screen coordinates, I don't understand exactly what you say, but if you said client coordinates (that is form, which is located relative to screen) then there is an easy way to get them to screen:
VB.NET:
Dim screenpoint As Point = Me.PointToScreen(New Point(clientX, clientY))
SendMessage(Me.Handle.ToInt32, WM_LBUTTONDOWN, 0, makeint32(screenpoint.X, screenpoint.Y))
SendMessage(Me.Handle.ToInt32, WM_LBUTTONUP, 0, makeint32(screenpoint.X, screenpoint.Y))
If you check with form mouse down/up event handler, you can see that the events are happening and can extract the coordinates that happened form there with e.X and e.Y.
 
Sending mouse clicks is always a hack for doing something that could be done in a better way. Tell us what you're trying to accomplish and we can help you with the best solution.
 
Back
Top