Several problems with that code...
First, mouse_event() should have Type Integer, not Long (that is a VB6 declaration):
<DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=Calling
Public Shared Sub mouse_event(ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
End Sub
Second, as pivar pointed out, you need to pass mouse_event() SCREEN coordinates. You can do this with PointToScreen():
Dim pt As Point = Me.PointToScreen(Button3.L
pt.Offset(Button3.Width / 2, Button3.Height / 2) ' get middle of the button
Finally, I moved the cursor using the built-in Cursor.Position() as this will allow it to work in 32 or 64 bit environments:
Public Sub DoMouseClick(ByVal pt As Point)
'Call the imported function with the cursor's current position
Cursor.Position = pt
mouse_event(MOUSEEVENTF_LE
End Sub
Here is the whole thing:
Main Topics
Browse All Topics





by: pivarPosted on 2009-10-29 at 03:54:14ID: 25692247
Hi,
e.com/Prog ramming/ Pr ogramming_ Languages/ Visual_Bas ic/Q_20834 312.html
You'll have to convert the position into screen coordinates and then convert it relative to a interval 0-65535.
Check this QA http://www.experts-exchang
Also be aware that mouse_event is being deprecated. SendInput is the new alternative.
/peter