-1

I have tried to make a programm that simulates mouse clicks and react on mouse click events in Visual Basic but I can't find what i need. I have written the code what i dont know logicly and marked it pls tell me the command of code what i need. Every where where is a # i don't know the code. Sorry for my brilliant englisch ;D my teacher is bad :P

Public Class Form1
Public Tick As Integer = 0
Public MaxTick As Integer = 0
Public active As Boolean = False

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    RadioButton1.Select()
    ComboBox1.SelectedIndex = 0
    ComboBox2.SelectedIndex = 0
End Sub

Private Sub RadioButton1_Change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.Click, RadioButton2.Click
    If RadioButton1.Checked Then
        GroupBox1.Enabled = True
        GroupBox2.Enabled = False
        Timer1.Interval = TextBox1.Text
    Else
        GroupBox2.Enabled = True
        GroupBox1.Enabled = False
        Timer2.Interval = TextBox3.Text
    End If
End Sub

Private Sub Me_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Tab) Then
        If RadioButton1.Checked Then
            active = False
            If Timer1.Enabled Then
                Timer1.Stop()
            Else
                Timer1.Start()
            End If
            e.Handled = False
        Else
            active = True
        End If
    End If
End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If CheckBoxLeft.Checked Then
        ###Perform Mouseclick Left###
    End If
    If CheckBoxMiddle.Checked Then
        ###Perform Mouseclick Middle###
    End If
    If CheckBoxRight.Checked Then
        ###Perform Mouseclick Right###
    End If
End Sub

###Private Sub OnClick_Event()###
    ###If Mouseclick == Right Then###
        If CheckBoxRight.Checked Then
            Timer2.start()
        End If
    ###Else if Mouseclick == Middle Then###
        If CheckBoxMiddle.Checked Then
            Timer2.Start()
        End If
    ###Else If Mouseclick == Left Then###
        If CheckBoxLeft.Checked Then
            Timer2.Start()
        End If
    End If
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    If active Then
        Tick += 1
        If CheckBoxLeft.Checked Then
            ###Perform Click Left###
        End If
        If CheckBoxMiddle.Checked Then
            ###Perform Click Middle###
        End If
        If CheckBoxRight.Checked Then
            ###Perform Click Right###
        End If
        If Tick = MaxTick Then
            Tick = 0
            Timer2.Stop()
        End If
    Else
        Timer2.Stop()
        Tick = 0
    End If
End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
    MaxTick = TextBox2.Text
End Sub
End Class

So i need a Mouseclick Event and then ask which Mousebutton was clicked and i need a method to perform left middle and right click

LG Niklas

  • I'm not sure what you are asking. If you want to click outside of the form, check this out: http://stackoverflow.com/questions/13532604/how-to-simulate-mouse-clicks – the_lotus Mar 23 '15 at 13:05

1 Answers1

0

You should look up the mouse_event() p/invoke method. This will allow you to simulate mouse events. It's declaration in VB.Net is

<DllImport("user32.dll")> _
Private Shared Sub mouse_event(dwFlags As UInteger, dx As UInteger, dy As UInteger, dwData As UInteger, dwExtraInfo As Integer)
End Sub

You can read more about it here. And here is a project on codeproject.com that has a complete example.

Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48