Govind
The One Musketeer
- Joined
- Apr 22, 2005
- Sythe Gold
- 23
- Messages
- 7,825
Get your hands on the freely available Visual Basic 2010 Express Edition.
If you have access to Microsoft DreamSpark, you can download Visual Studio 2010 Professional, which includes a better version of Visual Basic 2010, and various other languages.
On the New Project screen, create a new Windows Forms Application and name it AutoTyper. Press OK and the project will be created for you; a blank form design pane will appear on your screen. On the bottom-right corner of the screen, you will notice the Properties section. Under the Appearance subheading, change the Text field to "Auto Typer" (or whatever you want). You'll notice that after you hit Enter, the window title in the design pane changes from "Form1" to "Auto Typer".
Under the View menu, click Toolbox and the toolbox interface will pop up on the left side of the screen (click the thumbtack icon to fix the toolbox pane and realign the design pane correctly). Create two buttons and one text box, and, under the Components subsection, drag a Timer control onto the form (this will be invisible when you build your project into an executable). Lay them out however you want; this is the way I did it:
Rename the Text on one button to Start, and the other to Stop; also change their Name (first field under Design subheading) properties to startBtn and stopBtn respectively. Change the Name of the text box to typeTxt. These renamings are not necessary; it's just good to get in the habit of using descriptive and meaningful names for variables and controls. For example, if you ditch your project and come back to it months later, you may not remember what "Button1" was for, but if it was named "startBtn", that would give you some idea. Also, rename the Name on the Timer control from Timer1 to sendTimer. Double click the Start button, and a code window will appear. We're done with the n00b design phase; this is the real programming part
Your cursor will automatically go between those two lines. This event is fired whenever the Start button is clicked.
Add these lines between the Private Sub... and End Sub lines:
Basically, what this does is enable the timer to fire its own event every 2000 milliseconds. We are about to program that timer event.
Go back to the design screen and double click the Timer control below your form. The following procedure will automatically be created for you:
Between these two lines, add the following lines:
NOTE: If you changed the name of the TextBox control to anything other than "typeTxt", use that for the first line instead of typeText!
Basically, whenever the timer event occurs (every 2000 milliseconds), the contents of typeTxt will be sent as keystrokes to the target window, as will the Enter key.
Now, the last part...
Double click the Stop button, and add the following line in the newly-created procedure:
The logic behind this application is pretty easy to understand. Take a moment and think about it.
Challenge: make the Start and Stop buttons mutually exclusive - when the Timer is Enabled, the Start button will be Disabled (after all, it's meaningless when the timer is Enabled), and when the timer is not Enabled, the Stop button will be Disabled (after all, what's there to stop if there's no timer firing?)
Yes, that's a pretty simple challenge, but this is intended for really new programmers.
If you have access to Microsoft DreamSpark, you can download Visual Studio 2010 Professional, which includes a better version of Visual Basic 2010, and various other languages.
On the New Project screen, create a new Windows Forms Application and name it AutoTyper. Press OK and the project will be created for you; a blank form design pane will appear on your screen. On the bottom-right corner of the screen, you will notice the Properties section. Under the Appearance subheading, change the Text field to "Auto Typer" (or whatever you want). You'll notice that after you hit Enter, the window title in the design pane changes from "Form1" to "Auto Typer".
Under the View menu, click Toolbox and the toolbox interface will pop up on the left side of the screen (click the thumbtack icon to fix the toolbox pane and realign the design pane correctly). Create two buttons and one text box, and, under the Components subsection, drag a Timer control onto the form (this will be invisible when you build your project into an executable). Lay them out however you want; this is the way I did it:
Rename the Text on one button to Start, and the other to Stop; also change their Name (first field under Design subheading) properties to startBtn and stopBtn respectively. Change the Name of the text box to typeTxt. These renamings are not necessary; it's just good to get in the habit of using descriptive and meaningful names for variables and controls. For example, if you ditch your project and come back to it months later, you may not remember what "Button1" was for, but if it was named "startBtn", that would give you some idea. Also, rename the Name on the Timer control from Timer1 to sendTimer. Double click the Start button, and a code window will appear. We're done with the n00b design phase; this is the real programming part
Code:
Private Sub startBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startBtn.Click
End Sub
Your cursor will automatically go between those two lines. This event is fired whenever the Start button is clicked.
Add these lines between the Private Sub... and End Sub lines:
Code:
sendTimer.Enabled = True
sendTimer.Interval = 2000
Basically, what this does is enable the timer to fire its own event every 2000 milliseconds. We are about to program that timer event.
Go back to the design screen and double click the Timer control below your form. The following procedure will automatically be created for you:
Code:
Private Sub sendTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendTimer.Tick
End Sub
Between these two lines, add the following lines:
Code:
SendKeys.Send(typeTxt.Text())
SendKeys.Send("{enter}")
Basically, whenever the timer event occurs (every 2000 milliseconds), the contents of typeTxt will be sent as keystrokes to the target window, as will the Enter key.
Now, the last part...
Double click the Stop button, and add the following line in the newly-created procedure:
Code:
sendTimer.Enabled = False
The logic behind this application is pretty easy to understand. Take a moment and think about it.
Challenge: make the Start and Stop buttons mutually exclusive - when the Timer is Enabled, the Start button will be Disabled (after all, it's meaningless when the timer is Enabled), and when the timer is not Enabled, the Stop button will be Disabled (after all, what's there to stop if there's no timer firing?)
Yes, that's a pretty simple challenge, but this is intended for really new programmers.


