none
Auto clicker to send keystrokes RRS feed

  • Question

  • Hello,

    I'm setting up a little auto clicker for some friends for a game to send gifts.  Now and again theres a little popup that comes up and by pressing "enter" it clicks "send".

    What I have is the following:

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ComboBox1.Text = 2 Or 3 Or 4 Or 5 Then Timer1.Start()
            My.Computer.Keyboard.SendKeys("{ENTER}")
            Button1.BackColor = Color.Red
            Button2.Enabled = True
        End Sub

    However, the "clicking" works fine, but it won't send or repeat the "Sendkeys" for the Enter button..

    What I'm trying to do is:

    Set timer, press start, click (wait a few seconds) enter,, click (wait a few seconds) enter,, etc. (until stop button is pressed or hotkey is pressed)

    But what its doing is:

    click, click, click, click (keystroke won't send)

    How can I get the "keystroke" to repeat with the click until "stop" is clicked?

    Also, Is it possible to use hotkeys to start and stop with program/window being out of focus?


    • Edited by Trex2303 Friday, June 30, 2017 3:20 PM
    Friday, June 30, 2017 3:19 PM

All replies

  • Hello,

    I'm setting up a little auto clicker for some friends for a game to send gifts.  Now and again theres a little popup that comes up and by pressing "enter" it clicks "send".

    What I have is the following:

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If ComboBox1.Text = 2 Or 3 Or 4 Or 5 Then Timer1.Start()
            My.Computer.Keyboard.SendKeys("{ENTER}")
            Button1.BackColor = Color.Red
            Button2.Enabled = True
        End Sub

    However, the "clicking" works fine, but it won't send or repeat the "Sendkeys" for the Enter button..

    What I'm trying to do is:

    Set timer, press start, click,, enter,, click,, enter,, etc. (until stop button is pressed or hotkey is pressed)

    But what its doing is:

    click, click, click, click (keystroke won't send)

    How can I get the "keystroke" to repeat with the click until "stop" is clicked?

    Also, Is it possible to use hotkeys to start and stop with program/window being out of focus?

    I'm pretty sure the timer never starts - put a breakpoint on the tick event handler and see if it is entered.

    There is almost no chance that this line of code works:

    If ComboBox1.Text = 2 Or 3 Or 4 Or 5 Then Timer1.Start()

    This is going to resolve into:

    If ComboBox1.Text = 7

    Which will then do the implicit conversion from integer to string.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, June 30, 2017 3:24 PM
    Moderator

  • This is going to resolve into:

    If ComboBox1.Text = 7

    Which will then do the implicit conversion from integer to string.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    I had to think about this one.

    So because it's doing a bitwise operation, the result [has to be] an integer but because it's the .Text property, it will infer it as a string.

    ...and you wonder why I hate inference?!?

    ;-)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Friday, June 30, 2017 7:01 PM
  • I'm pretty sure the timer never starts - put a breakpoint on the tick event handler and see if it is entered.

    There is almost no chance that this line of code works:

    If ComboBox1.Text = 2 Or 3 Or 4 Or 5 Then Timer1.Start()

    This is going to resolve into:

    If ComboBox1.Text = 7

    Which will then do the implicit conversion from integer to string.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Actually, the timer starts and works just fine.  It does exactly what I wanted it to do.. (just click per seconds set)... If its set at 3 seconds, it will click every 3 seconds....  Obviously, I didn't show "everything" I have on form1....  The comboBox1.text is setup with this:

     Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    
            If ComboBox1.SelectedItem = 2 Then Timer1.Interval = 2000
    
            If ComboBox1.SelectedItem = 3 Then Timer1.Interval = 3000
    
            If ComboBox1.SelectedItem = 4 Then Timer1.Interval = 4000
    
            If ComboBox1.SelectedItem = 5 Then Timer1.Interval = 5000
    
        End Sub

    Does that make a bit more sense?

    Saturday, July 1, 2017 1:44 PM
  • T,

    At the top of your code, put the following:

    Option Strict On
    Option Explicit On
    Option Infer Off

    Do you see some problems with your code once you set those options?


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Saturday, July 1, 2017 2:23 PM
  • Food for thought:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Public Class Form1
        Private WithEvents tmr As Timer
    
    
    
        Private Sub _
            Form1_Load(sender As System.Object, _
                       e As System.EventArgs) _
                       Handles MyBase.Load
    
            Button1.Enabled = False
    
            With ComboBox1
                .Items.AddRange(New String() {"1", "2", "3", "4", "5"})
            End With
    
            tmr = New Timer
    
        End Sub
    
    
    
        Private Sub _
            ComboBox1_SelectedIndexChanged(sender As System.Object, _
                                           e As System.EventArgs) _
                                           Handles ComboBox1.SelectedIndexChanged
    
            If ComboBox1.SelectedIndex > -1 Then
                Button1.Enabled = True
            End If
    
        End Sub
    
    
    
        Private Sub _
            Button1_Click(sender As System.Object, _
                          e As System.EventArgs) _
                          Handles Button1.Click
    
            Button1.Enabled = False
            ComboBox1.Enabled = False
    
            Dim i As Integer
    
            If Integer.TryParse(ComboBox1.Text, i) Then
                If i >= 2 AndAlso i <= 5 Then
                    With tmr
                        .Interval = CInt(ComboBox1.Text) * 1000
                        .Enabled = True
                    End With
                End If
            End If
    
        End Sub
    
    
    
        Private Sub _
            tmr_Tick(sender As Object, _
                     e As System.EventArgs) _
                     Handles tmr.Tick
    
            tmr.Enabled = False
            Stop
    
        End Sub
    End Class


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Saturday, July 1, 2017 2:34 PM