Trying to make program to press a button every X minutes.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imhiya
    New Member
    • Nov 2006
    • 5

    Trying to make program to press a button every X minutes.

    Heres what ive got so far 0.o im more of a beginner Though =[

    Dim Tim As Integer
    Dim Often As Integer
    Dim EndT As Integer

    Private Sub cmdStart_Click( )
    Do 'Loop
    If Tim = Often Then
    SendKeys "A"
    Tim = 0
    End If
    Loop Until tmrEndT = EndT

    End Sub

    Private Sub Form_Load()
    txtEndT.Text = EndT
    tmrTim = Tim
    txtTim.Text = Often
    End Sub



    Im trying to make the program send the key A like it is being pressed or like if i opened notepad it would keep typing A every "often" for a total time of EndT
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by imhiya
    Heres what ive got so far 0.o im more of a beginner Though =[

    Dim Tim As Integer
    Dim Often As Integer
    Dim EndT As Integer

    Private Sub cmdStart_Click( )
    Do 'Loop
    If Tim = Often Then
    SendKeys "A"
    Tim = 0
    End If
    Loop Until tmrEndT = EndT

    End Sub

    Private Sub Form_Load()
    txtEndT.Text = EndT
    tmrTim = Tim
    txtTim.Text = Often
    End Sub



    Im trying to make the program send the key A like it is being pressed or like if i opened notepad it would keep typing A every "often" for a total time of EndT
    Hi. I think you are trying to use the timer control. This code works
    Code:
    Private Sub cmdStart_Click ()
       Timer1.Interval = CInt(Me.txtOften.Text) 'interval in milliseconds
       Timer1.Enabled = True
    End Sub
    
    Private Sub cmdEnd_Click()
       Timer1.Enabled = False
    End Sub
    
    'code is activated every time the timer event occurs
    Private Sub Timer1_Timer ()
       SendKeys "A"
    End Sub

    Comment

    • imhiya
      New Member
      • Nov 2006
      • 5

      #3
      Originally posted by willakawill
      Hi. I think you are trying to use the timer control. This code works
      Code:
      [B][I]Private Sub cmdStart_Click ()
         Timer1.Interval = CInt(Me.txtOften.Text) 'interval in milliseconds
         Timer1.Enabled = True
      End Sub[/I][/B]
      
      Private Sub cmdEnd_Click()
         Timer1.Enabled = False
      End Sub
      
      'code is activated every time the timer event occurs
      Private Sub Timer1_Timer ()
         SendKeys "A"
      End Sub

      can you explain the bold lines please ^^

      Comment

      • imhiya
        New Member
        • Nov 2006
        • 5

        #4
        Originally posted by imhiya
        can you explain the bold lines please ^^

        Btw is sendkey same as Keypress? cos i dont want it to type it i want it to think the button is being pressed on the keyboard

        Comment

        • willakawill
          Top Contributor
          • Oct 2006
          • 1646

          #5
          Originally posted by imhiya
          can you explain the bold lines please ^^
          You put a timer control on your form. The timer control interval must be set. In this example the timer is called Timer1 which is the default name for it when you add it to your form.

          Put a button to start the process on your form called cmdStart. The click event of this button will set the timer interval in milliseconds to whatever time interval you want. (1,000 milliseconds is one second). The maximum is 67,000 milliseconds which is just over a minute.

          The timer works when it is enabled so we set the enabled property to true when the start button is clicked.

          We set the enabled property to false when the end button is clicked.

          SendKeys will continually type the letter 'A' into any app that has the focus. If you test it with notepad you will see 'AAAAAAAA' continuing until the end button is clicked.

          I am not sure about your second question. Do you want to see the letter 'A' or whatever you choose in the notepad?

          Comment

          • imhiya
            New Member
            • Nov 2006
            • 5

            #6
            Originally posted by willakawill
            You put a timer control on your form. The timer control interval must be set. In this example the timer is called Timer1 which is the default name for it when you add it to your form.

            Put a button to start the process on your form called cmdStart. The click event of this button will set the timer interval in milliseconds to whatever time interval you want. (1,000 milliseconds is one second). The maximum is 67,000 milliseconds which is just over a minute.

            The timer works when it is enabled so we set the enabled property to true when the start button is clicked.

            We set the enabled property to false when the end button is clicked.

            SendKeys will continually type the letter 'A' into any app that has the focus. If you test it with notepad you will see 'AAAAAAAA' continuing until the end button is clicked.

            I am not sure about your second question. Do you want to see the letter 'A' or whatever you choose in the notepad?
            i got it to work ^.^ i put another text box for the button or letter i want to press for example i put {Tab} and it will press Tab. Also i make it so it times the txtOften by 1000 so i can set how many seconds i want :) Btw how do i make so it can go over 67k or just over a minute? Btw credits to you :P

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by imhiya
              Btw is sendkey same as Keypress? cos i dont want it to type it i want it to think the button is being pressed on the keyboard
              In a way, they are opposites. SendKey is the function you perform to send a key, while KeyPress is the event which is triggered when Windows says that the user pressed a key (and possibly when it receives the one you just sent).

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by imhiya
                i got it to work ^.^ i put another text box for the button or letter i want to press for example i put {Tab} and it will press Tab. Also i make it so it times the txtOften by 1000 so i can set how many seconds i want :) Btw how do i make so it can go over 67k or just over a minute? Btw credits to you :P
                One thing you could do is have it wait one second at a time (interval around 1,000), and count the elapsed time yourself. You might need to use a static variable to track the time since the last trigger.

                Comment

                Working...