473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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
7 4919
willakawill
1,646 1GB
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
imhiya
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
imhiya
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
willakawill
1,646 1GB
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
imhiya
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
Killer42
8,435 Expert 8TB
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
Killer42
8,435 Expert 8TB
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

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

Similar topics

3
by: aToaster | last post by:
Hey guys, I'm just getting the hang of Python and Tkinter and I could use some help. I wrote most of the gui for my calculator program, well I haven't gotten around to putting in the...
2
by: Just Me | last post by:
Need to write a program that wakes up every 15 minutes and does something. I guess I could just create a Windows application and schedule it to run every 15 minutes. Or I could have a program...
3
by: Dodger | last post by:
I've been working on this little doohickey for a bit now... (please ignore the speed issues of some of the queries -- things aren't all optimised up in mysql yet) ...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
1
by: xahlee | last post by:
Elisp Tutorial: Make Google Earth Xah Lee, 2006-12 This page shows a example of writing a emacs lisp function that creates a Google Earth file, and creates a link to the file, as well a link...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
4
by: boris.merryweather | last post by:
Hi, I'm VERY new to C#. I've bought a book (always a bad move) called "Build a Program Now. Visual C#" by Patrice Pelland. I got to chapter 4 without difficulty. I then started the project in...
2
Atran
by: Atran | last post by:
Hello: I have two programs (Windows Forms). I want to make the second program runs when I press a button in the first program. So when the user go to run the second program, I want the second...
5
by: clairelee0322 | last post by:
I am a C++ beginner and I am working on a C++ project that calucates the phone bill. I got stuck on how to make every 60 minutes into one hour.. Like if the user enter 1000 (10:00) and it asks for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.