By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

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

P: 5
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
Nov 6 '06 #1
Share this Question
Share on Google+
7 Replies


100+
P: 1,646
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdStart_Click ()
  2.    Timer1.Interval = CInt(Me.txtOften.Text) 'interval in milliseconds
  3.    Timer1.Enabled = True
  4. End Sub
  5.  
  6. Private Sub cmdEnd_Click()
  7.    Timer1.Enabled = False
  8. End Sub
  9.  
  10. 'code is activated every time the timer event occurs
  11. Private Sub Timer1_Timer ()
  12.    SendKeys "A"
  13. End Sub
  14.  
  15.  
  16.  
Nov 6 '06 #2

P: 5
Hi. I think you are trying to use the timer control. This code works
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdStart_Click ()
  2.    Timer1.Interval = CInt(Me.txtOften.Text) 'interval in milliseconds
  3.    Timer1.Enabled = True
  4. End Sub
  5.  
  6. Private Sub cmdEnd_Click()
  7.    Timer1.Enabled = False
  8. End Sub
  9.  
  10. 'code is activated every time the timer event occurs
  11. Private Sub Timer1_Timer ()
  12.    SendKeys "A"
  13. End Sub
  14.  
  15.  
  16.  

can you explain the bold lines please ^^
Nov 6 '06 #3

P: 5
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
Nov 6 '06 #4

100+
P: 1,646
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?
Nov 6 '06 #5

P: 5
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
Nov 6 '06 #6

Expert 5K+
P: 8,434
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).
Nov 6 '06 #7

Expert 5K+
P: 8,434
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.
Nov 6 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.