none
SendKeys.SendWait("{Enter}") RRS feed

  • Question

  • Hello,

    I set up a program for some friends of a group for the sole purpose of Game gifting.  (It's just a simple "auto-click").

    I have a timer set up for different amounts. 2-5 seconds.  What I'm trying to do is have it send a keystroke after it "clicks".


    Basically this:

    Selection of 3 seconds.  Click button to start, Program will auto click every 3 seconds.  Works fine no problems.


    Now I set up a second section for it to do the following:

    Selection of 3 seconds, click the button to start.  The timer counts 1,2,3 seconds, then send enter key... But it's not sending the enter key.

    Maybe I'm putting it in the wrong section?, even though I've tried it in multiple areas, but either way, it's not working.


    Here's an example:

    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
            If ComboBox2.SelectedItem = 2 Then Timer1.Interval = 2000
                    
            If ComboBox2.SelectedItem = 3 Then Timer1.Interval = 3000
            SendKeys.SendWait("{Enter}")
    
            If ComboBox2.SelectedItem = 4 Then Timer1.Interval = 4000
    
    
            If ComboBox2.SelectedItem = 5 Then Timer1.Interval = 5000
    
        End Sub

    I have also tried this as well:

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            If ComboBox2.Text = 2 Or 3 Or 4 Or 5 Then Timer1.Start()
            Button3.BackColor = Color.Red
            Button4.Enabled = True
            SendKeys.SendWait("{Enter}")
    
        End Sub

    But that one leads to a bad exception


    So what I want it to do is after the timer goes and it clicks, I also want it to send ENTER key after the click, and do this each time after each click.   

    3 seconds, Click, Enter,....3 Seconds, Click, Enter.

    But all it's doing is 3 seconds, Click.....3 Seconds, Click...


    Is there something else I need to add?  Or am I using Sendkeys wrong?

    I have also tried SendKeys.Send("{Enter}"), but that just gives an error.


    Saturday, October 6, 2018 1:43 PM

All replies

  • Hi

     SendKeys.Send("{ENTER}")

    works as expected here.

    What would your 'a bad exception' mean exactly?


    Regards Les, Livingston, Scotland

    Saturday, October 6, 2018 2:43 PM
  • If I use  SendKeys.Send("{ENTER}")  under Combobox, I get this:

    System.InvalidOperationException: 'SendKeys cannot run inside this application because the application is not handling Windows messages.  Either change the application to handle messages or use the SendKeys.SendWait method.'

    If I use SendKeys.Send("{ENTER}") under Button3_Click it lags everything really bad for about 7 - 10 seconds, but still doesn't use the "enter".  After the lag dissipates, it just does the normal timed click.

    If I use SendKeys.SendWait("{ENTER}") under Button3_Click, I get this:

    Exception of type 'System.StackOverflowException' was thrown.

    And if I use SendKeys.SendWait("{ENTER}") under Combobox, It doesn't do anything, Just the normal Timed click.



    Saturday, October 6, 2018 3:40 PM
  • Hi

    Are you sending 'ENTER to another running application ACTIVE window? If so, do you know if that external application can actually receive remote massages?


    Regards Les, Livingston, Scotland

    Saturday, October 6, 2018 4:19 PM
  • I was testing it using notepad. As far as I know, notepad can accept remote messages?
    Saturday, October 6, 2018 4:27 PM
  • Hi

    and was the NotePad window the active window?


    Regards Les, Livingston, Scotland

    Saturday, October 6, 2018 5:00 PM
  • Hi

    Try this out. Test by clicking Button1.

    ' Form1 with Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim Proc() As Process
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Process.GetProcessesByName("NotePad").Length = 0 Then
          Process.Start("NotePad")
        End If
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Proc = Process.GetProcessesByName("NotePad")
        AppActivate(Proc(0).Id)
        SendKeys.Send("{A}")
        SendKeys.Send("{ENTER}")
      End Sub
    End Clas


    Regards Les, Livingston, Scotland




    • Edited by leshay Saturday, October 6, 2018 5:34 PM
    Saturday, October 6, 2018 5:26 PM
  • Hi

    A version using a Timer. I still fail to understand exactly what you want. My interpretation so far is :

    User clicks Button3

    Button3 backgroundcolor changes to red

    Timer1 starts with Interval as per ComboBox2

    When Timer1 fires, sends ENTER (I send A also just to see something)

    Repeats each Timer Interval

    until user clicks Button4 (which I have set to: revert color on Button3, StopTimer1, disables Button4)

    Image

    Form1 Code

    ' Form1 with Button3, Button4
    ' Timer1 and Combobox2
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim Proc() As Process
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If Process.GetProcessesByName("NotePad").Length = 0 Then
          Process.Start("NotePad")
        End If
        ComboBox2.SelectedIndex = 0
      End Sub
      Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
        Timer1.Interval = CInt(ComboBox2.SelectedItem.ToString) * 1000
      End Sub
      Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Timer1.Enabled = True
        Button3.BackColor = Color.Red
        Button4.Enabled = True
      End Sub
      Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Timer1.Enabled = False
        Button3.BackColor = Color.FromKnownColor(KnownColor.Control)
        Button4.Enabled = False
      End Sub
      Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Proc = Process.GetProcessesByName("NotePad")
        AppActivate(Proc(0).Id)
        SendKeys.Send("{A}")
        SendKeys.Send("{ENTER}")
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Saturday, October 6, 2018 8:59 PM
    Saturday, October 6, 2018 8:58 PM
  • Hi Les,

    What the purpose would be is as follows:

    People load up a facebook game (We'll use Angry Birds as an example).

    They send gifts to friends.  Using the "auto clicker", You place the mouse over the "send gifts" button, and every 2,3,4 or 5 secs, it will "click" the Send gifts button.  Simple?  yes.

    Now once a week, you get an "extra" popup box, where when you send gifts, this popup box comes up where you check a box to "not ask again" blah blah till the next time.

    Now when including the "Enter" button, every time the auto clicker clicks "Send gifts", the popup box comes up and when you press "Enter" it clicks "OK".

    So, The auto clicker would Click the Send Gifts button, and then when the popup box comes up, it will auto hit Enter and automatically click the OK, then resumes to click.. etc.

    Does that help you understand it a bit more?

    Sunday, October 7, 2018 12:45 PM
  • Hi

    Seems like the code I posted could be adapted to suit your needs.


    Regards Les, Livingston, Scotland

    Sunday, October 7, 2018 1:56 PM