• 0

[VB 2005] simulate mouse clicks and movements


Question

hey, I'm trying to make something that can set the cursor in some point of the screen and click over there... my code is this:

Public Class Form1
	Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
	Public Declare Function SetCursorPos Lib "user32" (ByVal X As Integer, ByVal Y As Integer) As Long
	Public Const MOUSEEVENTF_LEFTDOWN = &H2
	Public Const MOUSEEVENTF_LEFTUP = &H4

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		SetCursorPos(Val(TextBox1.Text), Val(TextBox2.Text))
		mouse_event(&H2, Val(TextBox1.Text), Val(TextBox2.Text), 0, 0)
		mouse_event(&H4, Val(TextBox1.Text), Val(TextBox2.Text), 0, 0)
	End Sub
End Class

but I always get this error in the Public Const MOUSEEVENTF_LEFTDOWN = &H2 part:

A call to PInvoke function 'WindowsApplication1!WindowsApplication1.Form1::mouse_event' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

so what am I doing wrong? or what does that error means?... any help is appreciated

Edited by kachie

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.