Dopey-Rob

Is there any way to perform a click with code and not a mouse
This might be a silly question but I'm making a program that records your mouse movements, so that you don't have to keep doing tasks repetitively. I can only record the users mouse movements at the moment.

I would like to know if you can execute a mouse click with code
NOT button1.performclick!
I repeat

NOT button1.performclick!

lol xD Help pls

Thanks

Dopey as -Rob




Re: Visual Basic Express Edition Click :D

VBVB66

You could use: SendKeys.SendWait(" ")
A space being the key equivelent of a mouse click. I am pretty sure this only works for buttons though.





Re: Visual Basic Express Edition Click :D

Dave299

Do a Google search for mouse_event, which appears to do what you need. It has been superceded by SendInput but that appears to be difficult to use from VB.

I can't advise further as I've not used it.





Re: Visual Basic Express Edition Click :D

Riquel Dong ĘC MSFT

Hi Dopey,

Base on your post, my understanding of your question is that you need to use the code to trigger the Button click event. But you don't want to use the PerformClick method. You can use the SendMessage API to send Click message to the Button to achieve this.

Code Block

Public Class Form1

Public Declare Auto Function SendMessage Lib "user32.dll" Alias "SendMessage" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByRef lParam As IntPtr) As IntPtr

Const BM_CLICK As Integer = &HF5&

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Me.Timer1.Enabled = False

MessageBox.Show("click")

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

SendMessage(Me.Button2.Handle, BM_CLICK, 0, IntPtr.Zero)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.Timer1.Enabled = True

Me.Timer1.Interval = 100

End Sub

End Class

Best regards,

Riquel.






Re: Visual Basic Express Edition Click :D

jgalley

Code Block

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down

Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up

Code Block

'Set the mouse to the spot you want to click

Cursor.Position = New Point(100, 100)

'Send a mouse click event

mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

That will generate an "actual" click. You can simulate a click on many objects without usings this strategy though.